NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

Quikdav's avatar
Quikdav
Aspirant
Sep 30, 2011

Running PERL script in background

Hi all

I would like to run a PERL script as a background task on my NV+. This script will read a monitoring device connected on the USB port to monitor my electricity usage to write the result into a file.

I would like it start automatically when my NV+ start (after reboot for example)

So I wonder :

1 - where to run the script on the NAS ?

2 - what is the syntax to run it as a background task (perl my_script.pl &) ?

Thanks for your help

David

3 Replies

Replies have been turned off for this discussion
  • In order to do this, you will need to SSH into the NV box and do the following:


    1) Create a directory maybe in your /home directory
    2) Do a Chmod 755 on the new directory
    3) Place the perl script in that directory and Chmod 755
    4) You will need to edit your crontab file so that it will run your script at a certain time and interval.
    --The crontab file should be located at this path in the NV /usr/bin/crontab.
    --Edit it with your VI editor
    --Add something like this to the crontab file:
    30 11 * * * /your/directory/whatever.pl

    See this url for specific parameters that you can set on the crontab file: http://www.thesitewizard.com/general/set-cron-job.shtml

    I hope this helps.
  • Thanks for your reply Spiderman

    I don't want to run my script at a certain time and interval.

    I want to run it permanently. I found some information about the way to run script during NAS startup with /etc/rc3.d, /etc/rc0.d and /etc/init.d

    I'll look in that direction

    Thanks
  • Hi all

    I progressed in my research to run a PERL script as a daemon. So I created a script in inti.d and I'm testing it. It seems to be very simple but it doesn't works !!!

    When I run the script below, I have no error and I have message telling the script is running. The pid file is created but when I look for running daemons, I have nothing regarding it!!!

    I just want to run a Perl script with a parameter. So maybe I don't use the good value with start-stop-daemon arguments, I don't know !!!

    When I try my script, it work fine (/usr/bin/perl -I"/c/webroot/CurrentCostPerl/lib" /c/webroot/CurrentCostPerl/bin/current-cost-reader /dev/ttyUSB0)

    I tried to remove the -I argument for the PERL. I used the pragma "use lib" directly in my code. It has no effect. My daemon is not launching !!

    Does anyone have an idea. I think it must be a subtle but I tried so many cases !!!

    #!/bin/sh

    PATH=/usr/sbin:/usr/bin:/sbin:/bin
    DESC="Script PERL de monitoring du CurrentCost"
    NAME=CurrentCostPerlMonitoring
    DAEMON="/c/webroot/CurrentCostPerl/bin/current-cost-reader"
    DAEMON_ARGS="/dev/ttyUSB0"
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME
    DAEMON_OPT='-I"/c/webroot/CurrentCostPerl/lib"'

    test -f $DAEMON || exit 0

    set -e

    #
    # Function that starts the daemon/service
    #
    d_start()
    {
    start-stop-daemon --start --quiet --background --verbose --make-pidfile --pidfile $PIDFILE --exec /usr/bin/perl -- $DAEMON_OPT --startas $DAEMON $DAEMON_ARGS ||return 1
    }

    #
    # Function that stops the daemon/service.
    #
    d_stop()
    {
    start-stop-daemon --oknodo --stop --pidfile $PIDFILE --name skynet_perl --retry=TERM/30/KILL/5
    }

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    d_start
    echo "."
    ;;
    stop)
    echo -n "Stopping $DESC: "
    d_stop
    echo "."
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
    esac

    exit 0


    Thanks

    David

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More