My NSLU2 is generating new temperature graphs every 5 minutes from a network of 1-Wire sensors, but since it doesn’t have a connector for a screen I can’t look at the graphs unless I transfer the image files to my PC. Because my PC is sometimes turned off (scary stuff, I know ) I have to program the NSLU2 to transfer the files to an ‘always on’ server, and then from there download the graphs to my PC for analysis.
In order to program the NSLU2 I log in from my PC via my local network:
xx with the actual IP address of the NSLU2)
$ ssh email@example.com
I put the instructions for the NSLU2 in a script called
$ cd /home/thomas/rrdtool/ $ nano upload_graphs.sh
nano is a standard terminal text editor, and these are the commands that goes into the script:
#!/bin/bash sleep 30 lftp -u USER,PASSWORD SERVER <<EOF cd /temp/ lcd /home/thomas/rrdtool/ put temp_h.png put temp_d.png put temp_w.png put temp_m.png put temp_y.png quit 0 EOF
I immediately pause the script for 30 seconds to let the graph update script finish first before uploading the graph files.
lftp is an FTP client, and
cd means changing directory on the FTP server, whereas
lcd is a local change of directory.
On a standard NSLU2 Debian installation
lftp has to be installed before running the script:
$ means I’m working as a standard user, and
# means superuser)
$ su # apt-get install lftp # exit
The permission settings must be changed to ‘executable’ to allow the new script to execute:
$ chmod +x upload_graphs.sh
Test the script with a single run to see if it’s working correctly:
before adding it to the
$ crontab -e
This line in the
crontab list will execute the upload script every 5 minutes:
*/5 * * * * /home/thomas/rrdtool/upload_graphs.sh
crontab has been updated correctly:
$ crontab -l # m h dom mon dow command */5 * * * * /home/thomas/rrdtool/update_database.sh &> /dev/null */5 * * * * /home/thomas/rrdtool/upload_graphs.sh
Both the graph generation script and the upload script have now been installed as regular jobs to be run every 5 minutes.
Note: I realize that having your user name, password and server name in an
lftp script is not very secure, so if you have a better way of doing this, please leave a comment below.