bash script daemon


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script daemon
# 1  
Old 05-06-2012
bash script daemon

hi

I have the following script named ./daemonscript

Code:
while true
do
       #echo string to file results
	echo ok >> results
      #commands
	sleep 2
done

I call it the following way : ./daemonscript &

and I want it to stop when the user presses the "S" button together with the "Ctrl" button
How can I achieve that?

It's the first time I'm making something like that and I dont know even if I call it right because the file results doesnt show any message...Smilie
# 2  
Old 05-06-2012
Once you daemonize it, you lose control of it. You'll have to control it some other way than keypresses. You could have some other program which sends a signal to the daemon process on control-s, perhaps.
# 3  
Old 05-06-2012
Quote:
Originally Posted by Corona688
Once you daemonize it, you lose control of it. You'll have to control it some other way than keypresses. You could have some other program which sends a signal to the daemon process on control-s, perhaps.
Could you give me a simple example to understand what you mean exactly?
Is it better instead of running it as a daemon then to just run it with the while loop and stop it with the signal control-s?But in that case I would need an echo command and if the user doesn't press the control-s then it would wait instead of go on..
# 4  
Old 05-06-2012
Quote:
Originally Posted by vlm
Could you give me a simple example to understand what you mean exactly?
I can't really give you a simple example of something that can't work the way you want it to...
Quote:
Is it better instead of running it as a daemon then to just run it with the while loop and stop it with the signal control-s? But in that case I would need an echo command and if the user doesn't press the control-s then it would wait instead of go on..
I have no idea what you'd need an echo for, or why it'd need to wait for anything.

The easiest thing to do would be to just loop, and wait for the user to do ctrl-C, sigint. Then you could just let that break the loop, or trap it and change some variable. If it must be ctrl-s, you could do finicky things with stty to redefine ctrl-s as ctrl-c for the same effect.
# 5  
Old 05-06-2012
I think a better question might be why ctrl-s, and what's this daemon supposed to do.
# 6  
Old 05-07-2012
corona is right - instead of showing how you decided to do it, pretend you are just telling us what you are trying to do, and have no clue how to accomplish your task.

Aside from the fact that what you wrote is not a true daemon. And. It still has a process group with a controlling terminal. Among other issues.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to write a daemon script?

My requirement is to run two scripts simultaneously. Let say, script1.ksh is running in a loop : example: script1.ksh is: for i in 1 2 3 do script2.ksh 1 & #psedu code which is required to write here # if script 2.ksh is running, execute a script3.ksh (which actually check the... (2 Replies)
Discussion started by: sumitc
2 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

How to integrate all the systemctl commands into a shell script to verify any daemon/agent service?

Hi, Can we integrate all the systemctl command into a shell script to verify any service with all the options of systemctl if service integrate with the operating system service management tools to deliver their functionality. sudo systemctl start <service_name> sudo systemctl stop... (1 Reply)
Discussion started by: Mannu2525
1 Replies

4. Shell Programming and Scripting

How to make a bash or shell script run as daemon?

Say i have a simple example: root@server # cat /root/scripts/test.sh while sleep 5 do echo "how are u mate" >> /root/scripts/test.log done root@server # Instead of using rc.local to start or another script to check status, I would like make it as daemon, where i can do the following: ... (2 Replies)
Discussion started by: timmywong
2 Replies

5. Shell Programming and Scripting

script to run as a daemon

Hi, I have one query that is suppose if I have a script that pick up some files from source folder and put it into destination folder , and I want this script to run after every 1 hour, to make it configurable as per that I have options like crontab and nohup but when I test this script I have to... (2 Replies)
Discussion started by: nks342
2 Replies

6. Shell Programming and Scripting

run this script as a daemon process

Hi, HI , I have a simple script that moves files from one folder to another folder, I have already done the open-ssh server settings and the script is working fine and is able to transfer the files from one folder to another but right now I myself execute this script by using my creditianls to... (3 Replies)
Discussion started by: nks342
3 Replies

7. Shell Programming and Scripting

Doubt in the daemon running script

Hi I was going through one of my pjct script .Please let me know the logic for the deamon is running or not as i think the condtn should be vice-versa. daemon_list = 'idp1278' FAIL=0 for p in ${daemon_list} do fail=0 ps -fu workarea | grep ${p} > /dev/null 2>&1 if ] then ... (1 Reply)
Discussion started by: mani_isha
1 Replies

8. Shell Programming and Scripting

sample of script that control a daemon

Hi everybody, Does somebody has a sample of script that control a daemon? for example use loop until the daemon is on and if is not on do something else? Thanks Pier (0 Replies)
Discussion started by: pierrelaval
0 Replies

9. Shell Programming and Scripting

Run shell script as a daemon

I have simple shell script that I run as cron job every hour of the day. I would like to make it a daemon that runs far more frequently like every 30 seconds or so, but I have never made daemon before. How can I do this? -Sam (7 Replies)
Discussion started by: Sammy_T
7 Replies

10. Shell Programming and Scripting

shell script as a daemon

hi, can i run a shell script as a daemon ? the shell script looks like this : can this be run as a service ?: thanks regards shann (1 Reply)
Discussion started by: massoo
1 Replies
Login or Register to Ask a Question