Automatic File Transfer From NSLU2 to Server

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:

(Replace xx with the actual IP address of the NSLU2)

$ ssh thomas@192.168.1.xx

I put the instructions for the NSLU2 in a script called upload_graphs.sh:

$ 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:

$ ./upload_graphs.sh

before adding it to the crontab:

$ crontab -e

This line in the crontab list will execute the upload script every 5 minutes:

*/5 * * * * /home/thomas/rrdtool/upload_graphs.sh

Check if 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.

4 thoughts on “Automatic File Transfer From NSLU2 to Server

  1. Hi Thomas,
    first of all I would like to thank you for the excellent description that helped me very much.
    To avoid the ftp security issues I installed an apache webserver on my SLUG and copy now the generated pictures to a directory where my “html” files are located.

    Changes in “update_database.sh”, just add the new directory.
    rrdtool graph /khs/html/temp_h.png –start 1h etc, etc
    rrdtool graph /khs/html/temp_d.png –start 1d etc, etc

    Calling from my PC http://SLUG_IP/rrdtool.html shows me all the graphs on all computers at home.

    The example rrdtool.html to call the graphs.

    < !DOCTYPE html>

    img src=”temp_h.png” alt=”PNG Hours”

    img src=”temp_d.png” alt=”PNG Day”

    img src=”temp_w.png” alt=”PNG Week”

    img src=”temp_m.png” alt=”PNG Month”

    img src=”temp_y.png” alt=”PNG Year”


    There may be simpler ways, but that was quick and easy.
    Thank you Knut

    • Thank you for the tip, Knut!
      And I’m glad you found something useful.
      Did you post rrdtool.html? It doesn’t seem to show up in the comment above.

  2. Hello Thomas,
    last time I did post the rrdtool.html but it ended up in DOCTYPE and scrambled.
    Now another try without the fancy stuff like headers body, etc.

    –quote–

    –unquote–

    It shows the diagrams one over the other or a message mentioning the missing picture.
    Next step is to hook more DS1820 to the Slug.
    cu
    Knut

    • Mh, is it impossible to send html-code?
      Well, without all html-code.
      Please be so kind and clean it up ;-)
      –quote–
      img src=”temp_h.png” alt=”PNG Hours”

      img src=”temp_d.png” alt=”PNG Day”

      img src=”temp_w.png” alt=”PNG Week”

      img src=”temp_m.png” alt=”PNG Month”

      img src=”temp_y.png” alt=”PNG Year”
      –unquote–
      cu
      Knut

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>