From owner-freebsd-questions@FreeBSD.ORG Sun Feb 13 20:00:37 2005 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2AA4516A4CF for ; Sun, 13 Feb 2005 20:00:37 +0000 (GMT) Received: from viefep17-int.chello.at (viefep17-int.chello.at [213.46.255.23]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0FC3F43D1F for ; Sun, 13 Feb 2005 20:00:36 +0000 (GMT) (envelope-from gabor.kovesdan@t-hosting.hu) Received: from [80.99.33.169] by viefep17-int.chello.at (InterMail vM.6.01.03.05 201-2131-111-107-20040910) with ESMTP id <20050213200034.SHHO13802.viefep17-int.chello.at@[80.99.33.169]>; Sun, 13 Feb 2005 21:00:34 +0100 Message-ID: <420FB1E5.7020300@t-hosting.hu> Date: Sun, 13 Feb 2005 21:00:37 +0100 From: =?ISO-8859-1?Q?K=F6vesd=E1n_G=E1bor?= User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Paul Schmehl , freebsd-questions@freebsd.org References: <420FA6F5.1020609@t-hosting.hu> <042c01c51205$d0429c90$7702a8c0@officeeagle> In-Reply-To: <042c01c51205$d0429c90$7702a8c0@officeeagle> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: Crontab script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Feb 2005 20:00:37 -0000 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" > > To: > 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/