Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-10-2004, 03:08 PM
|
#1
|
|
Member
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418
Rep:
|
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
Last edited by Satriani; 12-10-2004 at 03:10 PM.
|
|
|
|
12-10-2004, 03:12 PM
|
#2
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
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
|
|
|
|
12-10-2004, 03:13 PM
|
#3
|
|
Member
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418
Original Poster
Rep:
|
I see what you mean, however, i want to be able to start it by hand in the first period...
|
|
|
|
12-10-2004, 03:19 PM
|
#4
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
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
|
|
|
|
12-10-2004, 03:26 PM
|
#5
|
|
Member
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418
Original Poster
Rep:
|
Running it as root was the trick i was lookin for! It now works!
thanks Cedrik!
|
|
|
|
12-10-2004, 03:29 PM
|
#6
|
|
Member
Registered: May 2003
Posts: 80
Rep:
|
you can use detachtty if you want to run it as a user.
|
|
|
|
12-10-2004, 03:49 PM
|
#7
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
or nohup
|
|
|
|
12-14-2004, 04:28 PM
|
#8
|
|
Member
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418
Original Poster
Rep:
|
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!
|
|
|
|
12-14-2004, 10:42 PM
|
#9
|
|
Senior Member
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,430
Rep:
|
nohup <script-name> &
-twantrd
|
|
|
|
12-16-2004, 06:39 AM
|
#10
|
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
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.
|
|
|
|
12-16-2004, 07:10 AM
|
#11
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
Also, look at this HTTPD server written in sh script. It is a good example of a sh TCP deamon ( Main URL)
Last edited by Cedrik; 12-16-2004 at 07:11 AM.
|
|
|
|
12-16-2004, 04:18 PM
|
#12
|
|
Member
Registered: Mar 2003
Location: The Netherlands
Distribution: Red Hat 7.3, Red Hat 9, Solaris8, Slackware 10, Slax on USB, AIX, FreeBSD, WinXP, AIX, Ubuntu
Posts: 418
Original Poster
Rep:
|
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)
|
|
|
|
03-29-2011, 05:23 PM
|
#13
|
|
LQ Newbie
Registered: Nov 2005
Distribution: debian
Posts: 10
Rep:
|
Quote:
Originally Posted by Cedrik
|
cute, but it's not a daemon, it appears to be a service that is launched on demand by sometheing like xinetd.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:57 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|