Getting script to run on boot up in linux

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2009
Posts: 3,462
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #11
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:
Running Monkey
==============

bin/monkey

or

bin/monkey -D (to run monkey in background mode)
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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #12
Oct 10th, 2009
Ok I'm not sure what this is telling you but

Shell Scripting Syntax (Toggle Plain Text)
  1. root@localhost:/etc# ls -alR /etc/rc.d/rc?.d
  2. /etc/rc.d/rc0.d:
  3. total 8
  4. drwxr-xr-x 2 root root 4096 Aug 10 2009 .
  5. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  6. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd
  7. lrwxrwxrwx 1 root root 20 Aug 10 2009 K31estar -> ../init.d/init_estar
  8. lrwxrwxrwx 1 root root 21 Aug 10 2009 K32monkey -> ../init.d/init_monkey
  9. lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa
  10. lrwxrwxrwx 1 root root 16 Apr 16 2009 K45random -> ../init.d/random
  11. lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp
  12. lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server
  13. lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap
  14. lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network
  15. lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd
  16. lrwxrwxrwx 1 root root 21 Apr 16 2009 S60sendsignals -> ../init.d/sendsignals
  17. lrwxrwxrwx 1 root root 17 Apr 16 2009 S70mountfs -> ../init.d/mountfs
  18. lrwxrwxrwx 1 root root 14 Apr 16 2009 S80swap -> ../init.d/swap
  19. lrwxrwxrwx 1 root root 18 Apr 16 2009 S90localnet -> ../init.d/localnet
  20. lrwxrwxrwx 1 root root 14 Apr 16 2009 S99halt -> ../init.d/halt
  21.  
  22. /etc/rc.d/rc1.d:
  23. total 8
  24. drwxr-xr-x 2 root root 4096 Oct 6 2008 .
  25. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  26. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd
  27. lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa
  28. lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp
  29. lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server
  30. lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap
  31. lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network
  32. lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd
  33. lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random
  34.  
  35. /etc/rc.d/rc2.d:
  36. total 8
  37. drwxr-xr-x 2 root root 4096 Nov 24 2008 .
  38. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  39. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd
  40. lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp
  41. lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server
  42. lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap
  43. lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network
  44. lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd
  45. lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random
  46.  
  47. /etc/rc.d/rc3.d:
  48. total 8
  49. drwxr-xr-x 2 root root 4096 Aug 14 2009 .
  50. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  51. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd
  52. lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network
  53. lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap
  54. lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random
  55. lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd
  56. lrwxrwxrwx 1 root root 20 Aug 10 2009 S40estar -> ../init.d/init_estar
  57. lrwxrwxrwx 1 root root 21 Aug 14 2009 S45monkey -> ../init.d/init_monkey
  58.  
  59. /etc/rc.d/rc4.d:
  60. total 8
  61. drwxr-xr-x 2 root root 4096 Oct 6 2008 .
  62. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  63. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd
  64. lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network
  65. lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap
  66. lrwxrwxrwx 1 root root 20 Apr 16 2009 S24nfs-server -> ../init.d/nfs-server
  67. lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random
  68. lrwxrwxrwx 1 root root 13 Apr 16 2009 S26ntp -> ../init.d/ntp
  69. lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd
  70.  
  71. /etc/rc.d/rc5.d:
  72. total 8
  73. drwxr-xr-x 2 root root 4096 Oct 6 2008 .
  74. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  75. lrwxrwxrwx 1 root root 18 Apr 16 2009 S10sysklogd -> ../init.d/sysklogd
  76. lrwxrwxrwx 1 root root 17 Apr 16 2009 S20network -> ../init.d/network
  77. lrwxrwxrwx 1 root root 17 Apr 16 2009 S22portmap -> ../init.d/portmap
  78. lrwxrwxrwx 1 root root 20 Apr 16 2009 S24nfs-server -> ../init.d/nfs-server
  79. lrwxrwxrwx 1 root root 16 Apr 16 2009 S25random -> ../init.d/random
  80. lrwxrwxrwx 1 root root 13 Apr 16 2009 S26ntp -> ../init.d/ntp
  81. lrwxrwxrwx 1 root root 14 Apr 16 2009 S30sshd -> ../init.d/sshd
  82.  
  83. /etc/rc.d/rc6.d:
  84. total 8
  85. drwxr-xr-x 2 root root 4096 Oct 6 2008 .
  86. drwxr-xr-x 11 root root 4096 Oct 6 2008 ..
  87. lrwxrwxrwx 1 root root 14 Apr 16 2009 K30sshd -> ../init.d/sshd
  88. lrwxrwxrwx 1 root root 14 Apr 16 2009 K35alsa -> ../init.d/alsa
  89. lrwxrwxrwx 1 root root 16 Apr 16 2009 K45random -> ../init.d/random
  90. lrwxrwxrwx 1 root root 13 Apr 16 2009 K46ntp -> ../init.d/ntp
  91. lrwxrwxrwx 1 root root 20 Apr 16 2009 K48nfs-server -> ../init.d/nfs-server
  92. lrwxrwxrwx 1 root root 17 Apr 16 2009 K49portmap -> ../init.d/portmap
  93. lrwxrwxrwx 1 root root 17 Apr 16 2009 K80network -> ../init.d/network
  94. lrwxrwxrwx 1 root root 18 Apr 16 2009 K90sysklogd -> ../init.d/sysklogd
  95. lrwxrwxrwx 1 root root 21 Apr 16 2009 S60sendsignals -> ../init.d/sendsignals
  96. lrwxrwxrwx 1 root root 17 Apr 16 2009 S70mountfs -> ../init.d/mountfs
  97. lrwxrwxrwx 1 root root 14 Apr 16 2009 S80swap -> ../init.d/swap
  98. lrwxrwxrwx 1 root root 18 Apr 16 2009 S90localnet -> ../init.d/localnet
  99. lrwxrwxrwx 1 root root 16 Apr 16 2009 S99reboot -> ../init.d/reboot
  100. 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*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #13
Oct 10th, 2009
Originally Posted by sknake View Post
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.
No idea, I didn't write the script. Can you update the script with what you think it should be and I'll try it with that.

Thanx for you help so far!
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,462
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
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:
  1. sk:/etc# find /etc -maxdepth 1 -iname \*rel\* ; find /etc -maxdepth 1 -iname \*ver\*
  2. /etc/squirrelmail
  3. [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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
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.
Last edited by iamthwee; Oct 10th, 2009 at 11:00 am.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,462
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
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.

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. #
  3. #
  4.  
  5. . /etc/rc.d/init.d/functions
  6.  
  7. EXE_DIR="/root/monkey-0.9.2/bin/"
  8. EXE_NAME="monkey"
  9.  
  10.  
  11. #############################################################
  12. #################### Functions ##############################
  13. #############################################################
  14.  
  15. function start {
  16. RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
  17. if [ $RUNNING -ge 1 ]; then
  18. echo "${EXE_NAME} is already running"
  19. echo_failure
  20. echo ""
  21. else
  22. if [ ! -x "${EXE_DIR}${EXE_NAME}" ]; then
  23. echo ""
  24. echo "[error] ${EXE_NAME} doesn't exist"
  25. echo_failure
  26. echo ""
  27. else
  28. # cd "${EXE_DIR}"
  29. # sleep 1
  30. # ./${EXE_NAME} > output &
  31. # disown
  32. ${EXE_DIR}${EXE_NAME} -D >> ${EXE_DIR}output 2>&1
  33. echo "Restarting ${EXE_NAME}"
  34. echo_ok
  35. echo ""
  36. fi
  37. fi
  38. }
  39.  
  40. function stop {
  41. echo ""
  42. echo "Stopping ${EXE_NAME}"
  43. RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
  44. if [ $RUNNING -ge 1 ]; then
  45. ID=`ps -ef | grep ${EXE_NAME} | grep -v grep | awk '{print $2}'`
  46. echo "PID= $ID"
  47. kill -9 $ID
  48. echo_ok
  49. echo ""
  50. else
  51. echo "${EXE_NAME} is not running"
  52. echo_failure
  53. echo ""
  54. fi
  55.  
  56.  
  57. return 0;
  58. }
  59.  
  60. function restart {
  61. stop
  62. start
  63. return 1;
  64. }
  65.  
  66. function status {
  67. RUNNING=`ps -ef | grep -c ./${EXE_NAME}\$`
  68. if [ $RUNNING -ge 1 ]; then
  69. echo "${EXE_NAME} Running"
  70. echo_ok
  71. echo ""
  72. tail -f "${EXE_DIR}output"
  73. else
  74. echo "${EXE_NAME} Not Running"
  75. echo_failure
  76. echo ""
  77. fi
  78. }
  79.  
  80. #############################################################
  81. ###################### MAIN #################################
  82. #############################################################
  83.  
  84.  
  85. case "$1" in
  86. start)
  87. start
  88. ;;
  89.  
  90. stop)
  91. stop
  92. ;;
  93.  
  94. restart)
  95. restart
  96. ;;
  97.  
  98. details|status)
  99. status
  100. ;;
  101.  
  102. *)
  103.  
  104. exit 1
  105. esac
  106.  
  107. 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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
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

Shell Scripting Syntax (Toggle Plain Text)
  1. > cd monkey-0.9.2
  2. > cd bin
  3. > ./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*
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,462
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
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 /root/monkey-0.9.2/bin/output have? Take a look at it: tail -50 /root/monkey-0.9.2/bin/output
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,462
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 629
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
0
  #19
Oct 10th, 2009
wait a minute.... you're running ./banana but the script you posted earlier references a different file:
Shell Scripting Syntax (Toggle Plain Text)
  1. EXE_DIR="/root/monkey-0.9.2/bin/"
  2. 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.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,275
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert
 
0
  #20
Oct 10th, 2009
The output is:

Shell Scripting Syntax (Toggle Plain Text)
  1. root@localhost:~/monkey-0.9.2/bin# more output
  2. Monkey HTTP Daemon 0.9.2
  3. Built : Aug 9 2009 22:38:40
  4. 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*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 1931 | Replies: 24
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC