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 and shell scripting languages 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 10:30 AM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM
Command doesn't work under cron ? bigjohn-nj Shell Programming and Scripting 4 01-20-2006 04:38 PM
ncopy doesn't work from cron Selma UNIX for Dummies Questions & Answers 2 01-20-2005 09:28 AM
Simple cron job won't work coregan UNIX for Dummies Questions & Answers 4 01-20-2004 05:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-04-2005
stancwong stancwong is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 31
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.
  #2 (permalink)  
Old 10-04-2005
nimish nimish is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 4
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
  #3 (permalink)  
Old 10-04-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,124
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:31 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0