The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
SCO Knew It Didn't Own Unix Copyrights, Court Ruling Suggests - DigitalJournal.com iBot UNIX and Linux RSS News 0 08-14-2007 06:30 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 06:52 PM
Command doesn't work under cron ? bigjohn-nj Shell Programming and Scripting 4 01-20-2006 12:38 PM
ncopy doesn't work from cron Selma UNIX for Dummies Questions & Answers 2 01-20-2005 05:28 AM
Simple cron job won't work coregan UNIX for Dummies Questions & Answers 4 01-20-2004 01:22 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2005
Registered User
 

Join Date: Aug 2005
Posts: 31
Stumble this Post!
script didn;t work in cron !!! @_@

Hi all,

I am writing a script to monitor some processes existence in the system. It works perfectly by running the script manually in commend line. However, when I put it under cron to run it failed. Everything time when the variable is null in the if statment. it failed and quitted. Here is part of my script.

****
NTP_STATUS=`ps -ef | grep xntp | grep -v grep`
if [ -z $NTP_STATUS ]
then
echo "WARNING - NTP daemon is not running"
else
echo "MESSAGE - NTP daemon is running"
fi
****

Therefore, when the variable NTP_STATUS is null, the script dropped out and quitted.

The weird thing is that it works fine when I run an script manually, but fails in cron....

please help guys. Thanks in advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 10-03-2005
Registered User
 

Join Date: Sep 2005
Posts: 4
Stumble this Post!
just change the following


i hope there is only one daemon process that you are looking for...
then

NTP_STATUS=`ps -ef | grep xntp | grep -v grep|wc -l`
if [ $NTP_STATUS < 1 ]
then
echo "WARNING - NTP daemon is not running"
else
echo "MESSAGE - NTP daemon is running"
fi

I hope this solves the problem.

Cheers
Nimish
Reply With Quote
  #3 (permalink)  
Old 10-04-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,424
Stumble this Post!
The original if statement will work only if xntp is running. To make it work if xntp is not running use quotes:
if [ -z "$NTP_STATUS" ]

The second if statement is wrong. < is for file redirection. You need a numeric compare anyway. So use -lt:
if [ $NTP_STATUS -lt 1 ]

You do not tell us what system or what shell you are using. So take the appropriate steps to ensure that cron will use the proper shell. If cron runs those commands with a different shell than the one you tested with, it may or may not work.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0