Sponsored Content
Top Forums Shell Programming and Scripting Creating a daemon to run in background Post 302496265 by ukndoit on Sunday 13th of February 2011 06:51:28 AM
Old 02-13-2011
Creating a daemon to run in background

I am trying to create a service to always run and monitor a script that has a tendency to hang, we could not find what is causing it to hang so are in the process of completely reprogramming just about everything, however, that will take upto 6 months.

So I need to create this to monitor the script to make sure it does not run wild which it does once in a while, sometimes only once per month, once per week or sometimes once per day or hour.

So here is what I am trying to do:

Get this code:
Code:
ps auxww | egrep [m]ember.cgi | awk '{print $2}' | while read PID; do kill -9 $PID; done;

to always be running in the background. I need the script to be allowed to run for at least 2 seconds before it would kill it, but i have no idea how to do that... Here is what I have so far and it does not work at all...

Code:
#!/bin/sh
#Kill_daemon.sh

i=0

while [$i -le 12]
do
ps auxww | egrep [m]ember.cgi | awk '{print $2}' | while read PID; do kill -9 $PID; done;
i++
sleep 5

done

however, when I try to execute it, I get this error:
: command not foundh: line 3:
: command not foundh: line 5:
Kill_daemon.sh: line 15: syntax error: unexpected end of file


I would appreciate any assistance you can provide, even if you can just point me in the correct direction. I am a novice in shell programming, I do not know much at all about it. I am a perl programmer and wrote a perl script to do it, however, when I keep it running, it holds the memory and cpu usage while sleeping, so the server load does not go down below .40 which if I don't have any of the scripts running wild and no perl script running to monitor it the server load gets down to like .10

Thank you much,
Richard
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

applicatoin cannot started, becos daemon did not run

hi, i had an applicatoin which is not running cos one of its daemon is not running.. i get the applicatoin to run by running the daemon first... its manual job... so quite cumbersome.. i have backups in the night, with the crontab -l entry with logs written. the logs indicated successful... (7 Replies)
Discussion started by: yls177
7 Replies

2. Shell Programming and Scripting

Creating a Daemon??

How in the world do you create a daemon and get it to start with a startup script? could someone tell me in detail im going nuts...thanks (1 Reply)
Discussion started by: nmajin
1 Replies

3. Programming

Creating a Daemon

how to convert a c program into a Daemon. thanks in advance svh (2 Replies)
Discussion started by: svh
2 Replies

4. UNIX for Dummies Questions & Answers

I would like to know Would you run the ‘identd’ daemon on UNIX servers?

Would you run the ‘identd' daemon on UNIX servers? can you please Explain. thanks in advance! (3 Replies)
Discussion started by: xoxouu
3 Replies

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

6. Shell Programming and Scripting

créating a daemon under unix

hi i want to create a daemon under unix or linux but i don't really know how so i will be grateful if you provide me links with examples or /andx how to do it thanks (2 Replies)
Discussion started by: student00
2 Replies

7. Shell Programming and Scripting

Creating background process for my shell

I actually posted this problem on a different forum, but figured this would be a more appropriate place to post it. OK so I've created my own shell, but I can't get the background process function to run properly! What I want to do is to run a process in the background, and also print when the... (2 Replies)
Discussion started by: hansel13
2 Replies

8. Shell Programming and Scripting

background scripts run-help

Looking for a logic where say i have a script called parent_script which is used to call other 4 to 5 child scripts in background as.. cat parent_script # containing 65 lines 1 2 .. 35 while read child_script 36 do 37 ./child_script_name& 38 done< ${SCRIPT_LISTS} 39 40 # Need to have... (2 Replies)
Discussion started by: michaelrozar17
2 Replies

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

10. 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
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 01:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy