Date: Sun, 13 Feb 2005 21:00:37 +0100 From: =?ISO-8859-1?Q?K=F6vesd=E1n_G=E1bor?= <gabor.kovesdan@t-hosting.hu> To: Paul Schmehl <pauls@utdallas.edu>, freebsd-questions@freebsd.org Subject: Re: Crontab script Message-ID: <420FB1E5.7020300@t-hosting.hu> In-Reply-To: <042c01c51205$d0429c90$7702a8c0@officeeagle> References: <420FA6F5.1020609@t-hosting.hu> <042c01c51205$d0429c90$7702a8c0@officeeagle>
next in thread | previous in thread | raw e-mail | index | archive | help
Hello, thanks a lot, it is a more advanced idea, I'll consider using it, but since then I've realized what caused my problem. I mistyped a line, and I should have written 2>&1 instead of 2>$1. I haven't been very advanced in shell scripting yet. :) Cheers, Gábor Paul Schmehl wrote: > ----- Original Message ----- From: "Kövesdán Gábor" > <gabor.kovesdan@t-hosting.hu> > To: <freebsd-questions@freebsd.org> > Sent: Sunday, February 13, 2005 1:13 PM > Subject: Crontab script > > >> Hi, >> >> I've seen somewhere an easy way to check whether a program with a >> specified pid is running or not. I've made a crontab script to check >> my programs based on this. The script is the following: >> >> #!/bin/sh >> PID_FILE="/usr/local/bopm/var/bopm.pid" >> PID=`cat $PID_FILE` >> EXECUTABLE="/usr/local/bopm/bin/bopm" >> > Check for a pid file is not a good way to see if a program is running. > *Sometimes* they will be running even though there is no pid file > (even though there's supposed to be one.) > > This would be bettter: > > either ps -auxw | grep {program name} | awk {'print $2'} > or pgrep {program name} (pgrep is available on the web) > > If you chose the former, you may have to put in a second grep to > eliminate "finding" your own command. Something like this: > ps -auxw | grep {program name} | grep {commandline switch of the > program} | awk {'print $2'} > > You will want to test this on the commandline first to make sure > you're getting the right process. > > Putting this all together then, with a specific example that I know > about: > > #!/bin/sh > > APACHE=/usr/local/sbin/apachectl > PID=`ps -auxw | grep httpd | grep "\-DSSL" | grep root | awk {'print > $2'}` > DATE=`date +"%m-%d-%H:%M:%S" > LOG=`tail /var/log/httpd-error.log` > > if [ ! -z $PID ]; then > $APACHE start > echo "Restarted apache at $DATE" > echo $LOG > fi > > This will check to see if it's running, and if it's not, start it and > send you the date/time it was started and the last 10 lines of the > error log. Since you're running it in cron, you'll get email with the > output. If you wanted, you could redirect stderr to a log to see if > there were any problems. > > Paul Schmehl (pauls@utdallas.edu) > Adjunct Information Security Officer > The University of Texas at Dallas > AVIEN Founding Member > http://www.utdallas.edu/~pauls/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?420FB1E5.7020300>