Visit Our UNIX and Linux User Community


How to write a daemon script?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to write a daemon script?
# 1  
Old 08-08-2019
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:
Code:
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 status of a table)
  # And if script2.ksh still running sleep for 60 seconds and again check the status by script3.ksh
  #Means in every 60 seconds scripts3.ksh needs to execute until script2.ksh finishes
  #once script2.ksh is not running, go at the for loop to run with next parameter to fire the script2.ksh
  # script2.ksh 2 &
done
--
script2.ksh
echo "Script 2 is running, which is actually a long running data processing script and updating the status of a table"
-----

Note: & I tried to run in background to note down the PID ($$) and tried to build the logic but as soon as I execute in background (&), it is not working properly. And if I don't run in background then it waits until script2.ksh finishes and its too late to check the staus that time via status3.ksh.

Hope I am able to explain the complex requirements.
Your help is highly appreciated.

Thanks,
Sumit

Last edited by jim mcnamara; 08-08-2019 at 10:00 AM..
# 2  
Old 08-08-2019
What "is not working properly"? Executing (long running) scripts in background is standard and should not lead to problems.
# 3  
Old 08-09-2019
Like this?
Code:
for i in 1 2 3
do
  script2.ksh $i &
  # if script 2.ksh is running, execute a script3.ksh (which actually check the status of a table)
  # And if script2.ksh still running sleep for 60 seconds and again check the status by script3.ksh
  while pgrep -f "script2.ksh $i"
  do
    script3.ksh
    sleep 60
  done
  #every 60 seconds scripts3.ksh needs to execute until script2.ksh finishes
  #once script2.ksh is not running, go at the for loop to run with next parameter to fire the script2.ksh
done


Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash script daemon

hi I have the following script named ./daemonscript 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... (5 Replies)
Discussion started by: vlm
5 Replies

2. 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

3. 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

4. IP Networking

read/write,write/write lock with smbclient fails

Hi, We have smb client running on two of the linux boxes and smb server on another linux system. During a backup operation which uses smb, read of a file was allowed while write to the same file was going on.Also simultaneous writes to the same file were allowed.Following are the settings in the... (1 Reply)
Discussion started by: swatidas11
1 Replies

5. Shell Programming and Scripting

How to write daemon in UNIX

Hi Guys, I hope this is the right forum to post this. I have a directory where files will be dumped at any time of the day and I want to run scripts as soon as new files come into the directory. How can I write a daemon that detects when new files have been uploaded to the directory? ... (1 Reply)
Discussion started by: regie101
1 Replies

6. 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

7. UNIX for Dummies Questions & Answers

How to write Pro*C daemon process using multithreading?

Hello, I am new to this forum and this is my first post here... I have never worked on either Pro*C or Multithreading..Now, i have to write a Pro*C, Multithreading daemon process.. I dont know where to start.. Can anybody help me with examples? 1. need to write a Pro*C multithreading... (0 Replies)
Discussion started by: kachiraju
0 Replies

8. Shell Programming and Scripting

How to write a daemon in Unix?

Hi I have a directory where sometimes a file will come (in a name format say file001.txt). I want to run a job (.ksh file) as soon as a new file comes into the directory. How can I write a shell script which will run in the background and monitor arrival of new file in the directory? ... (11 Replies)
Discussion started by: sbasak
11 Replies

9. 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

10. Programming

How to write daemon?

Hi , I want to know how to write a daemon process. I also want to know the concept behind daemon processes. Any material or sample program will be great :) . Thanks in advance -sg (2 Replies)
Discussion started by: sg6876
2 Replies

Featured Tech Videos