| | |
Getting script to run on boot up in linux
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Hi guys,
I've come to a road block so i need some help.
1)I have an exe which i need to run at start up.
So I put the following bash file in the inid.d directory:
The funny thing is the pid says it is running on boot. But it only works when I log on and restart the program manually?!
Any ideas?
I've come to a road block so i need some help.
1)I have an exe which i need to run at start up.
So I put the following bash file in the inid.d directory:
Shell Scripting Syntax (Toggle Plain Text)
#!/bin/bash # # . /etc/rc.d/init.d/functions EXE_DIR="/root/monkey-0.9.2/bin/" EXE_NAME="monkey" ############################################################# #################### Functions ############################## ############################################################# function start { RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$` if [ $RUNNING -ge 1 ]; then echo "${EXE_NAME} is already running" echo_failure echo "" else if [ ! -x "${EXE_DIR}${EXE_NAME}" ]; then echo "" echo "[error] ${EXE_NAME} doesn't exist" echo_failure echo "" else cd "${EXE_DIR}" sleep 1 ./${EXE_NAME} > output & disown echo "Restarting ${EXE_NAME}" echo_ok echo "" fi fi } function stop { echo "" echo "Stopping ${EXE_NAME}" RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$` if [ $RUNNING -ge 1 ]; then ID=`ps -ef | grep ${EXE_NAME} | grep -v grep | awk '{print $2}'` echo "PID= $ID" kill -9 $ID echo_ok echo "" else echo "${EXE_NAME} is not running" echo_failure echo "" fi return 0; } function restart { stop start return 1; } function status { RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$` if [ $RUNNING -ge 1 ]; then echo "${EXE_NAME} Running" echo_ok echo "" tail -f "${EXE_DIR}output" else echo "${EXE_NAME} Not Running" echo_failure echo "" fi } ############################################################# ###################### MAIN ################################# ############################################################# case "$1" in start) start ;; stop) stop ;; restart) restart ;; details|status) status ;; *) exit 1 esac exit 0
The funny thing is the pid says it is running on boot. But it only works when I log on and restart the program manually?!
Any ideas?
*Voted best profile in the world*
1
#2 Oct 10th, 2009
What do you mean "The funny thing is the pid says it is running on boot"? Scripts in init.d must be referenced from their run levels. Depending on your distro you should have a command for
Also the symlink naming convention for executing a process in the rc?.d directories is important. For example if monkey logs to syslog but starts before syslog is running then you may have a problem. HTTPDs are typically one of the last processes to start.
[edit]
One more thing .. usually scripts use pidfiles in /var/run . There are a lot of situations where
[/edit]
update-rc.d to specify the run levels to execute the scripts.Also the symlink naming convention for executing a process in the rc?.d directories is important. For example if monkey logs to syslog but starts before syslog is running then you may have a problem. HTTPDs are typically one of the last processes to start.
[edit]
One more thing .. usually scripts use pidfiles in /var/run . There are a lot of situations where
ps may not return what you expect. ie a user has a process start up with your exe's name which will cause your script to think it is already running, regardless of its current state.[/edit]
Last edited by sknake; Oct 10th, 2009 at 10:17 am.
0
#3 Oct 10th, 2009
>What do you mean "The funny thing is the pid says it is running on boot"?
Well the program (c++) is actually running on start up. You see it is mini light-weight webserver.
http://www.monkey-project.com/
However, when I go to the web page it comes up with the 404 page not found error. But when I restart the program manually from the terminal, it works fine.
>Depending on your distro you should have a command for update-rc.d to specify the run levels to execute the scripts.
At the moment I'm running it off a itx board that was compiled from scratch. I didn't do it so I'm kinda clueless. But if I can get this working in ubuntu for example it would be a start.
Thanx in advance.
Well the program (c++) is actually running on start up. You see it is mini light-weight webserver.
http://www.monkey-project.com/
However, when I go to the web page it comes up with the 404 page not found error. But when I restart the program manually from the terminal, it works fine.
>Depending on your distro you should have a command for update-rc.d to specify the run levels to execute the scripts.
At the moment I'm running it off a itx board that was compiled from scratch. I didn't do it so I'm kinda clueless. But if I can get this working in ubuntu for example it would be a start.
Thanx in advance.
*Voted best profile in the world*
0
#4 Oct 10th, 2009
Post the output for this
sk:/etc# ls -al rc?.d/ Your directory structure appears to be a little different in /etc so you may need to find where the rc?.d's are located: sk:/etc# find ./ -iname rc\*\.d 0
#5 Oct 10th, 2009
Here is how to add a script in debian (more or less the same in ubuntu, which is debian based):
http://74.125.47.132/search?q=cache:...&ct=clnk&gl=us
[edit]
/etc/init.d/skeleton contains a template for adding new startup scripts. You should be able to modify it to your needs
[/edit]
http://74.125.47.132/search?q=cache:...&ct=clnk&gl=us
[edit]
/etc/init.d/skeleton contains a template for adding new startup scripts. You should be able to modify it to your needs
[/edit]
Last edited by sknake; Oct 10th, 2009 at 10:31 am.
0
#6 Oct 10th, 2009
Here is my output:
Shell Scripting Syntax (Toggle Plain Text)
root@localhost:/etc# ls -al rc.d/ total 44 drwxr-xr-x 11 root root 4096 Oct 6 2008 . drwxr-xr-x 13 root root 4096 Jan 1 00:00 .. drwxr-xr-x 2 root root 4096 Aug 14 2009 init.d drwxr-xr-x 2 root root 4096 Aug 10 2009 rc0.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc1.d drwxr-xr-x 2 root root 4096 Nov 24 2008 rc2.d drwxr-xr-x 2 root root 4096 Aug 14 2009 rc3.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc4.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc5.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc6.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rcsysinit.d root@localhost:/etc# drwxr-xr-x 11 root root 4096 Oct 6 2008 . -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 13 root root 4096 Jan 1 00:00 .. -bash: drwxr-xr-x: command not found drwxr-xr-x 2 root root 4096 Aug 10 2009 rc0.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc1.d root@localhost:/etc# drwxr-xr-x 2 root root 4096 Aug 14 2009 init.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc4.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rc5.d -bash: drwxr-xr-x: command not found drwxr-xr-x 2 root root 4096 Oct 6 2008 rc6.d drwxr-xr-x 2 root root 4096 Oct 6 2008 rcsysinit.d root@localhost:/etc# drwxr-xr-x 2 root root 4096 Aug 10 2009 rc0.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Oct 6 2008 rc1.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Nov 24 2008 rc2.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Aug 14 2009 rc3.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Oct 6 2008 rc4.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Oct 6 2008 rc5.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Oct 6 2008 rc6.d -bash: drwxr-xr-x: command not found root@localhost:/etc# drwxr-xr-x 2 root root 4096 Oct 6 2008 rcsysinit.d -bash: drwxr-xr-x: command not found root@localhost:/etc#
*Voted best profile in the world*
0
#7 Oct 10th, 2009
eh that wasn't the command I posted.
ls -al rc?.d/ the ? expands for rc0.d/ rc1.d/ to list the directory contents, such as: text Syntax (Toggle Plain Text)
sk:/etc# ls -al rc?.d | less rc0.d: total 16 drwxr-xr-x 2 root root 4096 Mar 31 2007 . drwxr-x--x 129 root root 8192 Aug 17 18:30 .. lrwxrwxrwx 1 root root 17 Feb 12 2007 K09apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 14 Oct 15 2004 K11cron -> ../init.d/cron lrwxrwxrwx 1 root root 19 Oct 15 2004 K19setserial -> ../init.d/setserial lrwxrwxrwx 1 root root 14 Feb 8 2005 K20acct -> ../init.d/acct lrwxrwxrwx 1 root root 20 Dec 1 2005 K20bittorrent -> ../init.d/bittorrent lrwxrwxrwx 1 root root 17 Dec 19 2004 K20caudium -> ../init.d/caudium lrwxrwxrwx 1 root root 28 Oct 19 2004 K20courier-authdaemon -> ../init.d/courier-authdaemon lrwxrwxrwx 1 root root 22 Oct 19 2004 K20courier-imap -> ../init.d/courier-imap lrwxrwxrwx 1 root root 26 Oct 19 2004 K20courier-imap-ssl -> ../init.d/courier-imap-ssl lrwxrwxrwx 1 root root 21 Nov 23 2004 K20courier-pop -> ../init.d/courier-pop lrwxrwxrwx 1 root root 25 Nov 23 2004 K20courier-pop-ssl -> ../init.d/courier-pop-ssl lrwxrwxrwx 1 root root 16 Feb 25 2005 K20distcc -> ../init.d/distcc lrwxrwxrwx 1 root root 13 Mar 7 2007 K20gpm -> ../init.d/gpm lrwxrwxrwx 1 root root 17 Nov 24 2004 K20mailman -> ../init.d/mailman lrwxrwxrwx 1 root root 17 Oct 15 2004 K20makedev -> ../init.d/makedev lrwxrwxrwx 1 root root 15 Jul 14 2005 K20mbmon -> ../init.d/mbmon lrwxrwxrwx 1 root root 17 Oct 15 2004 K20oidentd -> ../init.d/oidentd lrwxrwxrwx 1 root root 23 Feb 26 2007 K20openbsd-inetd -> ../init.d/openbsd-inetd lrwxrwxrwx 1 root root 19 Feb 21 2005 K20pure-ftpd -> ../init.d/pure-ftpd lrwxrwxrwx 1 root root 15 Oct 18 2004 K20qmail -> ../init.d/qmail lrwxrwxrwx 1 root root 16 Nov 22 2004 K20quagga -> ../init.d/quagga lrwxrwxrwx 1 root root 15 Mar 18 2006 K20rsync -> ../init.d/rsync lrwxrwxrwx 1 root root 15 Oct 23 2004 K20snmpd -> ../init.d/snmpd lrwxrwxrwx 1 root root 13 Oct 15 2004 K20ssh -> ../init.d/ssh lrwxrwxrwx 1 root root 17 Mar 12 2007 K20sysstat -> ../init.d/sysstat lrwxrwxrwx 1 root root 16 Oct 23 2004 K20webmin -> ../init.d/webmin lrwxrwxrwx 1 root root 22 Nov 23 2004 K21spamassassin -> ../init.d/spamassassin lrwxrwxrwx 1 root root 13 Feb 1 2007 K23ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 20 Feb 22 2007 K25hwclock.sh -> ../init.d/hwclock.sh lrwxrwxrwx 1 root root 23 Oct 15 2004 K30etc-setserial -> ../init.d/etc-setserial lrwxrwxrwx 1 root root 18 Jun 20 2005 K40arpwatch -> ../init.d/arpwatch lrwxrwxrwx 1 root root 16 Nov 22 2004 K75hdparm -> ../init.d/hdparm lrwxrwxrwx 1 root root 18 Jan 25 2005 K79quotarpc -> ../init.d/quotarpc lrwxrwxrwx 1 root root 15 Oct 16 2004 K85bind9 -> ../init.d/bind9 lrwxrwxrwx 1 root root 15 Jan 25 2005 K85quota -> ../init.d/quota lrwxrwxrwx 1 root root 13 Nov 27 2004 K89atd -> ../init.d/atd lrwxrwxrwx 1 root root 15 Oct 15 2004 K89klogd -> ../init.d/klogd lrwxrwxrwx 1 root root 18 Oct 15 2004 K90sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 16 Oct 23 2004 K91apache -> ../init.d/apache lrwxrwxrwx 1 root root 20 Feb 27 2005 K91apache-ssl -> ../init.d/apache-ssl lrwxrwxrwx 1 root root 12 Oct 23 2004 K99ud -> ../init.d/ud -rw-r--r-- 1 root root 355 Jan 7 2006 README lrwxrwxrwx 1 root root 18 Feb 1 2007 S20sendsigs -> ../init.d/sendsigs lrwxrwxrwx 1 root root 17 Oct 15 2004 S30urandom -> ../init.d/urandom lrwxrwxrwx 1 root root 22 Oct 15 2004 S31umountnfs.sh -> ../init.d/umountnfs.sh lrwxrwxrwx 1 root root 20 Oct 15 2004 S35networking -> ../init.d/networking lrwxrwxrwx 1 root root 18 Oct 15 2004 S40umountfs -> ../init.d/umountfs lrwxrwxrwx 1 root root 20 Sep 12 2005 S60umountroot -> ../init.d/umountroot lrwxrwxrwx 1 root root 14 Oct 15 2004 S90halt -> ../init.d/halt rc1.d: total 16 drwxr-xr-x 2 root root 4096 Mar 31 2007 . drwxr-x--x 129 root root 8192 Aug 17 18:30 .. lrwxrwxrwx 1 root root 17 Feb 12 2007 K09apache2 -> ../init.d/apache2 lrwxrwxrwx 1 root root 14 Oct 15 2004 K11cron -> ../init.d/cron lrwxrwxrwx 1 root root 14 Feb 8 2005 K20acct -> ../init.d/acct lrwxrwxrwx 1 root root 17 Dec 19 2004 K20caudium -> ../init.d/caudium lrwxrwxrwx 1 root root 28 Oct 19 2004 K20courier-authdaemon -> ../init.d/courier-authdaemon
0
#9 Oct 10th, 2009
Oh right not sure, I'm completely lost when it comes to shell scripting and linux
Shell Scripting Syntax (Toggle Plain Text)
root@localhost:/etc# find ./ -iname rc\*\.d ./rc.d ./rc.d/rc6.d ./rc.d/rc2.d ./rc.d/rc0.d ./rc.d/rcsysinit.d ./rc.d/rc1.d ./rc.d/rc5.d ./rc.d/rc3.d ./rc.d/rc4.d root@localhost:/etc#
*Voted best profile in the world*
0
#10 Oct 10th, 2009
Ok -- now try this:
It will be a lot of output so you have two options
1) Write it to a file:
2) Use a pager:
ls -alR /etc/rc.d/rc?.d It will be a lot of output so you have two options
1) Write it to a file:
ls -alR /etc/rc.d/rc?.d >> /tmp/outfile 2) Use a pager:
ls -alR /etc/rc.d/rc?.d | less or ls -alR /etc/rc.d/rc?.d | more . Your system may not have one of the pagers installer. In my opinion less > more, but either will work. ![]() |
Similar Threads
- Python Script for windows & linux (Python)
- How to modify this perl script and make it running in Linux , solaris and windowXP? (Perl)
- wxpython gdk error on fedora 5 (fc5) (Python)
- Linux Shell Script needs help writing program (Shell Scripting)
- could an old machine run linux (Getting Started and Choosing a Distro)
- Boot Linux after instaling windows (*nix Software)
Other Threads in the Shell Scripting Forum
- Previous Thread: This is the error i get when i run my script: Unmatched `
- Next Thread: Changing a string in 1500 documents
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






