On 5/3/06, Kapil Sethi <[EMAIL PROTECTED]> wrote: > > Hi Abhishek, > > I checked the mails after a long time so my suggestions are late. Anyways > I > hope it helps. > > ===================================================== > > Dear Friends, > I again have a question(looks like i have a lot of questions:) ) > I need a shell script run as a cron to do the following task, > 1)Do 'ps -ef' or with other arguments of 'ps ' and see whether a > particular process is executing. Pl. tell me what are the best parameters > of 'ps' to search for a particular process > 2) If yes do nothing. > 3)If no runs that same process. > 4)Logs all messages to a file > 5)Logs all error messages to another file. > I am a novice at shell script. > Pl. help me give some inputs , regarding the best parameters /arguments of > > 'ps' and whas the method of logging error and normal messages. > Thakns, > -- > Regards, > Abhishek Jain > > ========================================================== > > In situations like above, I prefer to let cron do the job of launching as > scheduled at regular intervals. > > I would let the script check if any previous instance is running. If there > is no previous instance then continue else exit gracefuly > > echo "Starting script at `date`" > if [ -f /var/run/script.lck ]; then > echo "Old Lock file found" > PID1=`/var/run/script.lck` > if [ -z "`ps -ef | grep $PID1 | grep -v grep`" ]; then > echo "Looks previous instance exited uncleanly" > echo $$ > /var/run/script.lck > echo "Starting new instance" > else > echo "Previous instance already running" > exit 1 > fi > else > echo $$ > /var/run/script.lck > echo "Starting new instance" > fi > > .... > .... > > and at the end > > rm -f /var/run/script.lck > > cron can redirect the output and errors from the script to separate files. > > Kapil > > > > > _______________________________________________ > ilugd mailinglist -- ilugd@lists.linux-delhi.org > http://frodo.hserus.net/mailman/listinfo/ilugd > Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi > http://www.mail-archive.com/ilugd@lists.linux-delhi.org/ > > > Hi all, Sorry again for the delayed response, I have made a PHP script with an infinite loop and sleep after every 30 secs and an entry at rc.local to start it itself when server restarts, I wanted to know that can this solve the purpose, I do not find any problem in the last week as it working fine apart from the fact that it is not logging correctly as i have had placed a logrotate on the script , the logging is ok initially but when the log file is changed by logrotate the logging stops and the new log file is 0 byte size . The entry at rc.local is /var/www/vhosts/file.php >>/var/www/vhosts/output.log 2>&1
Can anyone explain the reason for so. Thanks, Abhishek Jain _______________________________________________ ilugd mailinglist -- ilugd@lists.linux-delhi.org http://frodo.hserus.net/mailman/listinfo/ilugd Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi http://www.mail-archive.com/ilugd@lists.linux-delhi.org/