script didn;t work in cron !!! @_@


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script didn;t work in cron !!! @_@
# 1  
Old 10-04-2005
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  
Old 10-04-2005
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  
Old 10-04-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Crontab] didn't work

Hello, Here is my crontab # Reboot one Sunday out of 2 at 02:00 0 2 * * 0/2 /usr/bin/reboot 2017-04-16 2017-04-23 2017-04-30 and so on I tested my crontab here, it seems to work Http://cron.schlitt.info/index.php?c...=100&test=Test However on my distrib linux mageďa When I register... (4 Replies)
Discussion started by: amazigh42
4 Replies

2. AIX

Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again: Runnning a cron job every 5 mins to send data files to a state facility. My original cron entry at worked fine: 01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh Somewhere I have a... (1 Reply)
Discussion started by: Skyybugg
1 Replies

3. UNIX for Dummies Questions & Answers

emulate aix 5.3 , how ....? pearpc didn't work

how to emulate aix 5.3 i had try pearpc , but it didn't work ... someone have some solution? thanks (1 Reply)
Discussion started by: prpkrk
1 Replies

4. SCO

Hard disk clone of OpenServer 5.0.0 didn't work, why?

Continuing saga of working on making a retail store more robust by creating a backup clone of the main server, a 1995 era :eek: PC running SCO OpenServer 5.0.0b and a discontinued Point of Sales (POS) software system. I have a PC of the same make and model. The CPU runs faster and it has a... (5 Replies)
Discussion started by: jgt10
5 Replies

5. Shell Programming and Scripting

awk: assign variable with -v didn't work in awk filter

I want to filter 2nd column = 2 using awk $ cat t 1 2 2 4 $ VAR=2 #variable worked in print $ cat t | awk -v ID=$VAR ' { print ID}' 2 2 # but variable didn't work in awk filter $ cat t | awk -v ID=$VAR '$2~/ID/ { print $0}' (2 Replies)
Discussion started by: honglus
2 Replies

6. Shell Programming and Scripting

SED - replace with new line didn´t work for solaris

Hi This is what I was trying to do, comment one line and add something different in a new line right next. This is the command I want to do more .profile | sed 's,STRING1, #STRING1 NEWLINE STRING2,' (I´m using ',' because my string is something like this exec... (3 Replies)
Discussion started by: alcalina
3 Replies

7. Shell Programming and Scripting

Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen. When I run... (2 Replies)
Discussion started by: RoshniMehta
2 Replies

8. UNIX for Dummies Questions & Answers

starce didn't work

Hello, I am learning to debug in sgi-Irix6.5, after a core dump, I was adviced to perform a "strace", but I got the following information: ERROR: tracer already exists what shall I do now? Thanks a lot Daniel (0 Replies)
Discussion started by: lakeat
0 Replies

9. Shell Programming and Scripting

script to start DB didn't work, help

I have created a script to strat and shutdown Oracle 10g DB on Solaris automatically when UNIX reboot. In the begining, it worked well. All of sudden, the dbstart part didn't work, other 3 part for lsnrctl, emctl, isqlplusctl all worked fine. I think it was TNS_ADMIN variable got problem. Because... (0 Replies)
Discussion started by: duke0001
0 Replies

10. Shell Programming and Scripting

mail program on shell script didn't work, please advise.

Hi, everyone: I post a new thread because previous post may sink and I hope the new one can be caught by your eyes. I created a shell script and the script works fine. However, the mail program part on script didn't send email to my email box and it also didn't provide any traceable... (7 Replies)
Discussion started by: duke0001
7 Replies
Login or Register to Ask a Question