LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 12-10-2004, 03:08 PM   #1
Satriani
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: Reputation: 30
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.
 
Old 12-10-2004, 03:12 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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
 
Old 12-10-2004, 03:13 PM   #3
Satriani
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: Reputation: 30
I see what you mean, however, i want to be able to start it by hand in the first period...
 
Old 12-10-2004, 03:19 PM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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
 
Old 12-10-2004, 03:26 PM   #5
Satriani
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: Reputation: 30
Running it as root was the trick i was lookin for! It now works!

thanks Cedrik!
 
Old 12-10-2004, 03:29 PM   #6
SerfurJ
Member
 
Registered: May 2003
Posts: 80

Rep: Reputation: 15
you can use detachtty if you want to run it as a user.
 
Old 12-10-2004, 03:49 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,481

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
or nohup
 
Old 12-14-2004, 04:28 PM   #8
Satriani
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: Reputation: 30
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!
 
Old 12-14-2004, 10:42 PM   #9
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
nohup <script-name> &

-twantrd
 
Old 12-16-2004, 06:39 AM   #10
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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.
 
Old 12-16-2004, 07:10 AM   #11
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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.
 
Old 12-16-2004, 04:18 PM   #12
Satriani
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: Reputation: 30
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)
 
Old 03-29-2011, 05:23 PM   #13
j13ett5
LQ Newbie
 
Registered: Nov 2005
Distribution: debian
Posts: 13

Rep: Reputation: 1
Exclamation

Quote:
Originally Posted by Cedrik View Post
Also, look at this HTTPD server written in sh script. It is a good example of a sh TCP deamon ( Main URL)
cute, but it's not a daemon, it appears to be a service that is launched on demand by sometheing like xinetd.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems in running a script as a daemon at startup fahad26 Programming 5 03-07-2012 07:24 AM
Run my bash script as a daemon. jaimese Linux - Newbie 12 02-10-2011 03:28 PM
Running two copy's of the same bash script AndiOliver Programming 2 10-06-2004 03:46 AM
Running script as daemon StinkyFinger Linux - Newbie 2 08-28-2003 07:31 PM
Running bash script files in C++ (Kylix) Acherion Programming 4 07-25-2003 11:35 PM


All times are GMT -5. The time now is 06:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration