Run perl script on startup in Ubuntu

I have a perl script that I need to run once at startup with an argument under my user account .

So when I boot the system, it needs to execute a command like this,

./path/to/script.pl start 

Any ideas?

+4
source share
3 answers

You can use the string in your crontab (crontab -e)

To run a command at startup:

edit / etc / crontab Add the following line:

@reboot root perl./path/to/ script.pl start

^^^ Run as root. Change β€œroot” to β€œBlackCow” to launch BlackCow

Or you can use upstart (add the .conf file to / etc / init /). Here's a copy and paste from my notes:

Use upstart to start the daemon on reboot / start

e.g.. / etc / init / prestocab.conf:

 #!upstart description "node.js server" author "BlackCow" start on (local-filesystems and net-device-up IFACE=eth0) stop on shutdown script export HOME="/root" exec sudo -u root /usr/local/bin/node /home/prestocab/prestocab.com/www/socket.io/server.js 2>&1 >> /var/log/prestocab.log end script 

For use:

 start prestocab stop prestocab restart prestocab 

# You might want to use some kind of process monitor to restart the daemon if it fails

+7
source

Depending on what you use init , if your version of Ubuntu uses upstart

you need to configure the appropriate Upstart startup scripts, if not rc scripts based on your runlevel . Check update-rc.d .

+3
source

In Ubuntu, the easiest way is to add this line to your /etc/rc.local file (up to line exit 0 , substituting username with your own username):

 su -c "./path/to/script.pl start" username & 
+2
source

All Articles