| | |
Getting script to run on boot up in linux
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
0
#11 Oct 10th, 2009
I have looked at the source and I have a question. In your init script you have
From the INSTALL file:
Shouldn't you be using -D to put it in Daemon/background mode instead of using &? Also your redirect only handles stdout but not stderr, and if something isn't initializing properly it will probably write to stderr. It should look like:
./${EXE_NAME} > output & where the & is apparently how you're trying to make it a background process.From the INSTALL file:
•
•
•
•
Running Monkey
==============
bin/monkey
or
bin/monkey -D (to run monkey in background mode)
./${EXE_NAME} >> output 2>&1 & . Using ">" overwrites the file if it exists, or creates a new file where ">>" appends or creates a new file so your log will keep growing. 0
#12 Oct 10th, 2009
Ok I'm not sure what this is telling you but
Btw the script I gave in post #1 works fine to start up a c++ exe I've written myself if it means I don't have to use the SKELETON one you suggested.
Shell Scripting Syntax (Toggle Plain Text)
root@localhost:/etc# ls -alR /etc/rc.d/rc?.d /etc/rc.d/rc0.d: total 8 drwxr-xr-x 2 root root 4096 Aug 10 2009 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 20 Aug 10 2009 K31estar -> ../init.d/init_estar lrwxrwxrwx 1 root root 21 Aug 10 2009 K32monkey -> ../init.d/init_monkey lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa lrwxrwxrwx 1 root root 16 Apr 16 2009 K45random -> ../init.d/random lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 21 Apr 16 2009 S60sendsignals -> ../init.d/sendsignals lrwxrwxrwx 1 root root 17 Apr 16 2009 S70mountfs -> ../init.d/mountfs lrwxrwxrwx 1 root root 14 Apr 16 2009 S80swap -> ../init.d/swap lrwxrwxrwx 1 root root 18 Apr 16 2009 S90localnet -> ../init.d/localnet lrwxrwxrwx 1 root root 14 Apr 16 2009 S99halt -> ../init.d/halt /etc/rc.d/rc1.d: total 8 drwxr-xr-x 2 root root 4096 Oct 6 2008 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random /etc/rc.d/rc2.d: total 8 drwxr-xr-x 2 root root 4096 Nov 24 2008 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random /etc/rc.d/rc3.d: total 8 drwxr-xr-x 2 root root 4096 Aug 14 2009 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 20 Aug 10 2009 S40estar -> ../init.d/init_estar lrwxrwxrwx 1 root root 21 Aug 14 2009 S45monkey -> ../init.d/init_monkey /etc/rc.d/rc4.d: total 8 drwxr-xr-x 2 root root 4096 Oct 6 2008 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 20 Apr 16 2009 S24nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random lrwxrwxrwx 1 root root 13 Apr 16 2009 S26ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd /etc/rc.d/rc5.d: total 8 drwxr-xr-x 2 root root 4096 Oct 6 2008 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 20 Apr 16 2009 S24nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random lrwxrwxrwx 1 root root 13 Apr 16 2009 S26ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd /etc/rc.d/rc6.d: total 8 drwxr-xr-x 2 root root 4096 Oct 6 2008 . drwxr-xr-x 11 root root 4096 Oct 6 2008 .. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa lrwxrwxrwx 1 root root 16 Apr 16 2009 K45random -> ../init.d/random lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd lrwxrwxrwx 1 root root 21 Apr 16 2009 S60sendsignals -> ../init.d/sendsignals lrwxrwxrwx 1 root root 17 Apr 16 2009 S70mountfs -> ../init.d/mountfs lrwxrwxrwx 1 root root 14 Apr 16 2009 S80swap -> ../init.d/swap lrwxrwxrwx 1 root root 18 Apr 16 2009 S90localnet -> ../init.d/localnet lrwxrwxrwx 1 root root 16 Apr 16 2009 S99reboot -> ../init.d/reboot root@localhost:/etc#
Btw the script I gave in post #1 works fine to start up a c++ exe I've written myself if it means I don't have to use the SKELETON one you suggested.
*Voted best profile in the world*
0
#13 Oct 10th, 2009
•
•
•
•
I have looked at the source and I have a question. In your init script you have./${EXE_NAME} > output &where the & is apparently how you're trying to make it a background process.
From the INSTALL file:
Shouldn't you be using -D to put it in Daemon/background mode instead of using &? Also your redirect only handles stdout but not stderr, and if something isn't initializing properly it will probably write to stderr. It should look like:./${EXE_NAME} >> output 2>&1 &. Using ">" overwrites the file if it exists, or creates a new file where ">>" appends or creates a new file so your log will keep growing.
Thanx for you help so far!
*Voted best profile in the world*
0
#14 Oct 10th, 2009
That output tells me that your init script is referenced in runlevels 0 (halt) and 3 (depends on distro). What distro is that machine running?
"Standard": 3 Multi-User Mode with Networking Starts the system normally
Debian: 2-5 are same
Redhat: Multi-User mode, console logins only
SuSE: 3 Multi-User mode, console logins only
Slackware: 3 Multi-User mode without display manager
So depending on what distro you're using that may be the wrong runlevel. One way of finding the distro:
I think redhat creates /etc/redhat-release .. but most all distros have a file named "release" or "version" in /etc.
"Standard": 3 Multi-User Mode with Networking Starts the system normally
Debian: 2-5 are same
Redhat: Multi-User mode, console logins only
SuSE: 3 Multi-User mode, console logins only
Slackware: 3 Multi-User mode without display manager
So depending on what distro you're using that may be the wrong runlevel. One way of finding the distro:
text Syntax (Toggle Plain Text)
sk:/etc# find /etc -maxdepth 1 -iname \*rel\* ; find /etc -maxdepth 1 -iname \*ver\* /etc/squirrelmail [COLOR="Red"]/etc/debian_version[/COLOR]
I think redhat creates /etc/redhat-release .. but most all distros have a file named "release" or "version" in /etc.
0
#15 Oct 10th, 2009
Erm I vaguely remember the guy saying something about using linux from scratch? Does that matter?
I mean if that makes things a bit more easier.
I'll forget that for the time being and just try to get this working at start up for ubuntu as a vmware image?
But I really need this to work on start up.
I mean if that makes things a bit more easier.
I'll forget that for the time being and just try to get this working at start up for ubuntu as a vmware image?
But I really need this to work on start up.
Last edited by iamthwee; Oct 10th, 2009 at 11:00 am.
*Voted best profile in the world*
0
#16 Oct 10th, 2009
Ok.. try this. kill the httpd, backup your file, replace it with this, and see if it starts. If it starts OK then try rebooting the machine.
After the machine reboots examing the contents of the log file and see if it even tried to execute. If it didn't execute then we'll add it to the other standard startup runlevels.
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 ${EXE_DIR}${EXE_NAME} -D >> ${EXE_DIR}output 2>&1 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
After the machine reboots examing the contents of the log file and see if it even tried to execute. If it didn't execute then we'll add it to the other standard startup runlevels.
0
#17 Oct 10th, 2009
Ok I just tried that new script, but it didn't work.
The webpage still failed to load.
[edit]
Out of interest does it work on your machine.
To see it working you should be able to open your webbrowser, type in: localhost:2001
And it should server out the web page.
in order to start the exe manually, you go to
This is of course after you've ran the config and make file.
The webpage still failed to load.
[edit]
Out of interest does it work on your machine.
To see it working you should be able to open your webbrowser, type in: localhost:2001
And it should server out the web page.
in order to start the exe manually, you go to
Shell Scripting Syntax (Toggle Plain Text)
> cd monkey-0.9.2 > cd bin > ./banana restart
This is of course after you've ran the config and make file.
Last edited by iamthwee; Oct 10th, 2009 at 11:11 am.
*Voted best profile in the world*
0
#18 Oct 10th, 2009
There could be a million things going wrong with the distro being LFS. Up for doing a gotomeeting or logmein and I can take a look at it? That would be the easiest way 
With the new script is the daemon running? What does the contents of

With the new script is the daemon running? What does the contents of
/root/monkey-0.9.2/bin/output have? Take a look at it: tail -50 /root/monkey-0.9.2/bin/output 0
#19 Oct 10th, 2009
wait a minute.... you're running
Those are running two different files in the bin directory .. unless they're symlinked to eachother?
[edit]
I don't know if it will work on my machines. It requires a ton of libs that I don't have installed.
[/edit]
./banana but the script you posted earlier references a different file: Shell Scripting Syntax (Toggle Plain Text)
EXE_DIR="/root/monkey-0.9.2/bin/" EXE_NAME="monkey"
Those are running two different files in the bin directory .. unless they're symlinked to eachother?
[edit]
I don't know if it will work on my machines. It requires a ton of libs that I don't have installed.
[/edit]
Last edited by sknake; Oct 10th, 2009 at 11:20 am.
0
#20 Oct 10th, 2009
The output is:
Which is probably useless no doubt.
Again, have you tried getting it to work for your linux distro.
If you can get it to run at start up that would be encouraging.
Not sure how to do the logmein. Is it something you gotta pay for?
Thanx again.
Shell Scripting Syntax (Toggle Plain Text)
root@localhost:~/monkey-0.9.2/bin# more output Monkey HTTP Daemon 0.9.2 Built : Aug 9 2009 22:38:40 Home : http://monkeyd.sourceforge.net
Which is probably useless no doubt.
Again, have you tried getting it to work for your linux distro.
If you can get it to run at start up that would be encouraging.
Not sure how to do the logmein. Is it something you gotta pay for?
Thanx again.
*Voted best profile in the world*
![]() |
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
Views: 1931 | Replies: 24
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting






