LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   nohup help (https://www.linuxquestions.org/questions/programming-9/nohup-help-866590/)

rvaede 03-05-2011 09:14 AM

nohup help
 
I need help adding a nohup command in this command line:
su - rhx12 -c "/rhythx/rhythx/bin start /rhythx/rhyth"
When I execute the script using root on the command line it works fine.
But, when I reboot the server the process doesn't start.

This script will go into the etc/init.d and rc2.d directory.

#!/bin/bash
case $1 in
start)
su - rhx12 -c "/rhythx/rhythx/bin start /rhythx/rhythx"
;;
stop)
su - rhx12 -c "/rhythx/rhythx/bin stop /rhythx/rhythx"
;;
*)
echo "should be command stop or start"
;;
esac

David the H. 03-05-2011 10:30 AM

First, please don't double-post. Choose only one forum that you think best matches your topic. I'm responding to this one because it's a scripting question.

Second, please use [code][/code] tags around your code, to preserve formatting and to improve readability.

Code:

case $i in
What is $i? It's not defined anywhere in the script, so I can't imagine it would work at all. Do you perhaps mean $1?

rvaede 03-05-2011 11:21 AM

Yes thats correct, it should be $1.
I am at home and I don't have access to the work network so I entered the script from memory.

archtoad6 03-07-2011 12:14 PM

Please edit your post to put the code in a Code block, as suggested above. It will make your post easier to read, & that will get you more, better, & faster help.

rvaede 03-08-2011 06:42 AM

Thanks I was able to fix this.

archtoad6 03-08-2011 07:17 AM

2 of us, one Senior Member & one Moderator, have nicely asked you to edit your post which started this thread.
  1. Why have you not complied w/ these polite requests?
  2. Do you need help finding the "Edit" button?
  3. Is my earlier link to info on Code blocks not clear?

rvaede 03-09-2011 06:59 AM

I fixed the code using the edit link.
The link you provided did not help find the solution.
But, its a useful link.

regards

jschiwal 03-09-2011 07:14 AM

Quote:

This script will go into the etc/init.d and rc2.d directory.
If that is true, the script will be running as the root user, so you don't need to use su - preceding the command.

The command wouldn't run because it is an interactive command expecting a password entered, which won't happen when running as a startup script.

Be careful with automated scripts such as cron scripts for example. For cron scripts you aren't attached to a terminal, so you can't get input from stdin. There is no stdout, so either redirect output to /dev/null or a log file.
Also, nohup isn't used for scripts already running in the background.

Look at the skeleton file in /etc/init.d/. It is a model of what a script in init.d should look like. You left out the headers that inserv and chkconfig use.

In rc2.d/ you should have a properly named link to the script in init.d/. Don't put scripts in their.

You might want to read the man pages for insserv, chkconfig and init.d.

(note: some distro's don't use chkconfig.)


All times are GMT -5. The time now is 10:23 AM.