4

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 up it needs to execute a command like this,

./path/to/script.pl start

Any ideas?

BlackCow
  • 1,437
  • 2
  • 14
  • 11

3 Answers3

7

You could use a line 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

^^^ Runs as root. Change "root" to "BlackCow" to run as BlackCow

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

Use upstart to run a daemon at 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

To use:

start prestocab
stop prestocab
restart prestocab

# You might want to use some sort of process monitor to restart the daemon if it crashes

Eamorr
  • 9,872
  • 34
  • 125
  • 209
3

Depends on what init you are using, if your version of Ubuntu is using upstart

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

Ani
  • 1,448
  • 1
  • 16
  • 38
2

On Ubuntu, the simplest way is to add this line to your /etc/rc.local file (before the exit 0 line, substituting username with your own user name):

su -c "./path/to/script.pl start" username &
Árpád Szász
  • 161
  • 3
  • 2