bash script running as daemon
Hi all,
I have written a bash script to ease my administration. However, what i would like is, whenever i start this program, it will immediately get in the background and "daemonizes". (Meaning, that it will keep running, even if i log out.) Is this possible with bash-scripts??? If it works as i expected, i would like to run it as service at startup (put it in the rc.d or rc.local orso), but it should also work as executable.... thanks for your help! Satch |
Did you try to put:
/path/to/your/script & in /etc/rc.d/rc.local so it start at boot, run in background, and keep running even if you log out |
I see what you mean, however, i want to be able to start it by hand in the first period...
|
You could try your program with & to test it in background, but to keep it running out of the user
session I think you have to run it as root |
Running it as root was the trick i was lookin for! It now works!
thanks Cedrik! |
you can use detachtty if you want to run it as a user.
|
or nohup
|
Mmm.. how should i run it then?
Should i enter something like that in the script? If you could give an code-example, that would be great! |
nohup <script-name> &
-twantrd |
Since you are using Redhat you have a script handy which will launch a process as a daemon. The script is /etc/rc.d/init.d/functions and you could source that in your script and launch the process like this:
. /etc/rc.d/init.d/functions daemon /path/to/my/script This is from memory so you should double check the functions script to verify exactly how to call the daemon function. |
Also, look at this HTTPD server written in sh script. It is a good example of a sh TCP deamon ( Main URL)
|
Thanks bin/bash, but i am currently ot using RH, but Slackware... (Should update my profile, as you pointed me to this)
I could look in the script, i have a redhat machine somewhere..... :) Also followd the link to that sh_httpd but it didn't help me further (yet) |
Quote:
|
All times are GMT -5. The time now is 12:34 PM. |