Community
OpenEnergyMonitor

Community

Command Line Cheatsheet

Tags: #<Tag:0x00007f8df5840a50>

If you’d like to add your own command line tip please reply to this post
 

How to login to the raspberry pi via terminal (SSH)

ssh [email protected]*** (*** = or IP-address from Pi or domain name)

Password = emonpi2016 (standard password if you didn’t change it)

Connecting via ssh


Safely shutdown or reboot a raspberry pi
after you logged in via SSH you can issue these commands

shutdown :

sudo shutdown -h now

-or-

sudo poweroff

reboot :

sudo shutdown -r now

-or-

sudo reboot

Factory Reset
Factory reset can be made by connecting via ssh then running:

sudo su
~/emonpi/./factoryreset

Warning - destroys all data!
https://guide.openenergymonitor.org/setup/troubleshooting/#factory-reset

Maintain crontab files

List cron for user Pi

crontab -l -u pi

List cron for root

sudo crontab -l		

Edit cron for user Pi *

crontab -e -u pi

Edit cron for root *

sudo crontab -e		

* for low-write emon devices, use rpi-rw to unlock filesystem and allow write access.


Determine emonSD image version

ls /boot | grep emonSD

Display_PHPfina_Feed_Interval
To determine feed interval and start time of feed.

cd /home/pi/data/phpfina
od -i 1.meta

response:

0000000       0       0       10     1435712370
0000020

10 is interval in seconds
1435712370 is start time in unix epoch

Submitted by chaveiro on Mon, 27/07/2015 - 12:30


Get status of all Services
Runs all init scripts, in alphabetical order, with the status command. The status is:
[ + ] for running services
[ - ] for stopped services and
[ ? ] for services without a ‘status’ command

sudo service --status-all

 



#emon Node-RED
including npm & node.js
 

Status or Restart of Node-RED Service
Use the below commands to get the status or restart Node-RED

sudo service nodered status
sudo service nodered restart

Version number of Node-RED

npm show node-red version
npm show node-red version -g

Node-RED items in syslog
Display Node-RED items saved in syslog

sudo cat /var/log/syslog | grep "Node-RED"

Output Node-RED items in syslog

sudo tail -f /var/log/syslog | grep "Node-RED"

Version of npm
npm is used for installing installing nodes for Node-RED

npm -v
sudo npm -v

List user installed Nodes with version info
run command from the Node-RED install directory

cd /home/pi/.node-red
npm list -g | grep emoncms
npm list | grep emoncms

Upgrade of NPM version 1.x to version 2.x *

sudo npm install -g [email protected]
logout

* for low-write emon devices, use rpi-rw to unlock filesystem and allow write access.


Check for outdated Node-RED npm packages

npm outdated --prefix ~/.node-red

-or-

cd ~/.node-red
npm outdated

to check for outdated global npm packages:

npm outdated -g

Version of node.js

node -v
sudo node -v

Check if Redis is running

redis-cli PING

If running, the response should be “PONG”


Flush Redis

redis-cli flushall

 



#emon mySQL
 
Access mySQL database
for advanced users only (this leaves me out!)

mysql -u emoncms -p emonpiemoncmsmysql2016 emoncms

Show emoncms tables

mysql> show tables;

Display Feed info
Display ID number, feed id Name, Tag for feed, Datatype (realtime, daily, etc), Public (or private), Size of feed, Engine used for feed (phpfina or phptimeseries, etc.), and Process List for all Feeds

mysql> select * from feeds;

 



#Miscellaneous

 
Selectively monitor log file in real time
Display new lines with a string (e.g., “NEW FRAME : OK 5”) in the emonhub.log file:

tail -f /var/log/emonhub/emonhub.log | grep "NEW FRAME : OK 5"

Selectively display log file
Display all lines with a string (e.g., “NEW FRAME : OK 5”) in the emonhub.log file:

cat /var/log/emonhub/emonhub.log | grep "NEW FRAME : OK 5"

 
Display all lines with two strings (e.g., “mqtt” or “mosquitto”) in the syslog file:

cat /var/log/syslog | grep -ie mqtt -e mosquitto

 

Thank you to @Paul, @bidouilleur, @Bill.Thomson, @Robert.Wall, @glyn.hudson, @pb66 for their help in creating this post.

1 Like

Resetting the emonCMS password

Can be done locally, or via SSH.
This assumes your emoncms admin account user name, and your database, are both named emoncms. If not, substitute your admin account username where you see the emoncms username, and your database name where you see the emoncms database name.

Create a new user from the emoncms login screen. For this example, we’ll give that user the name emontemp.

Take note of the password you gave the emontemp user.

Run Mysql as the MySQL root user:

mysql -u root -p (you’ll be prompted for the MySQL root user password)

Switch to your database. Substitute your database name if it’s not emoncms.
use emoncms

Copy emontemp’s password to the emoncms user account:

update users set password=(select * from (select password from users where username='emontemp') x) where username='emoncms'; (Substitue your username if it’s not emoncms.)

Copy emontemp’s password salt to the emoncms user account:

update users set salt=(select * from (select salt from users where username='emontemp') x) where username='emoncms';

Time saver tip: The two commands are the same save for the words password and salt. After you issue the first command, hit the up arrow key, change the two instances of password to salt, hit enter.
That’s it. You should be able to log on to your emoncms admin account with the password you gave emontemp.