LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Running Perl Script upon startup (https://www.linuxquestions.org/questions/linux-software-2/running-perl-script-upon-startup-315430/)

andy7t 04-20-2005 04:36 PM

Running Perl Script upon startup
 
I have a perl script that I need to run when my computer starts.
It must run as root.
I'm using Suse 9.1 Personal.

peter72 04-20-2005 05:43 PM

2 possible solutions that I can think of to do this.

1. Make it a service. Have to make a start up script (bourne shell usually) and link the script to whatever run level directory you want it to start at ( probable 5 ).
2. Add the perl script to the a similar init script ( ie. if it is a network thing, then add the /etc/init.d/network script ). This is cheating, and not really advisable, but definately the easiest method.

basic startup script follows:

#########################
# start some process
#########################

RETVAL=0
case "$1" in
start)
/yourpathtoscript/script.pl
;;
stop)
## pkill very dangerous, ensure the perl script name is unique
pkill script.pl
;;
status|restart|reload)
;;
*)
echo "Usage: sysstat {start|stop|status|restart|reload}"
exit 1
esac
exit $RETVAL
######
## end of script
######

make script executable and copy to /etc/init.d/

Then you need to decide the run_level ( probable 5 ) and do either symbolic link to /etc/rc5.d

# cd /etc/rc5.d
# ln -s ../init.d/yourstartscript S99yourstartscript

The S99 is order in which it is started. You can also ( and should ) make a K99yourstartscript, which will properly kill the process on reboots and changes to the run-level.

I probable forgot something, but this should get you started.

Pete


All times are GMT -5. The time now is 04:12 PM.