From owner-freebsd-questions Sun Nov 24 13:16:32 2002 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 5577337B401 for ; Sun, 24 Nov 2002 13:16:29 -0800 (PST) Received: from the-frontier.org (ns1.the-frontier.org [216.86.199.114]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9260343EA3 for ; Sun, 24 Nov 2002 13:16:28 -0800 (PST) (envelope-from pscott@skycoast.us) Received: from [192.168.66.249] (dhcp-249-66-168-192.the-frontier.org [192.168.66.249]) by the-frontier.org (8.9.3/8.9.3) with ESMTP id NAA05348; Sun, 24 Nov 2002 13:15:39 -0800 (PST) (envelope-from pscott@skycoast.us) User-Agent: Microsoft-Entourage/10.1.1.2418 Date: Sun, 24 Nov 2002 13:15:38 -0800 Subject: Re: .sh interactive ok, from crontab, not From: "Paul A. Scott" To: Len Conrad , Message-ID: In-Reply-To: <5.1.1.6.2.20021124194251.02c390c0@mail.go2france.com> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > From: Len Conrad > This snippet works fine... > > if ( ps aux | grep -i "^root.*master" ) > /dev/null > then > echo "then: exit code equal 0" > exit 0 > else > > > ... when run from the command line, the echo text displays. But, when run > from crontab every 10 minutes, the if fails, and the else clause runs. > > I've tried every syntax I know, but still can't get this logic to work. It works for me, and I suspect that it's working for you, too. However, you may not see the results expected if you are piping the cron output through sendmail, because the 'echo "then: ...' could be interpreted as a mail header. Make certain that you output a blank line, eg., echo "", *before* any lines that contain 'some-word:' so that sendmail stops looking for headers. Just a guess. Also, make sure that you're running the expected shell. Check the SHELL= line in crontab, or force the script to run via the expected shell by running 'sh script' instead of just 'script', or tell the script what shell to run by adding something like the following on the first line: #!/bin/sh Although this isn't related to your problem , you might find it simpler to use the -q option on grep instead of redirecting the output. For example, if ( ps -aux | grep -q -i "^root.*master" ); then instead of, if ( ps aux | grep -i "^root.*master" ) > /dev/null; then Paul -- Paul A. Scott mailto:pscott@skycoast.us http://skycoast.us/pscott/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message