Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errors when running script from cron

Status
Not open for further replies.
Oct 9, 2003
174
US
hey guys

I have a script that I wrote that runs fine when i call it manually but I receive errors when running it from the cron. Here are the errors:

Your "cron" job on enterprise
/morgan/bin/system_test.scr

produced the following output:

/morgan/bin/system_test.scr[25]: ping: not found
/morgan/bin/system_test.scr[37]: tnsping: not found
/morgan/bin/system_test.scr[37]: test: argument expected
/morgan/bin/system_test.scr[37]: tnsping: not found
/morgan/bin/system_test.scr[37]: test: argument expected
/morgan/bin/system_test.scr[37]: tnsping: not found
/morgan/bin/system_test.scr[37]: test: argument expected
/morgan/bin/system_test.scr[37]: tnsping: not found
/morgan/bin/system_test.scr[37]: test: argument expected
/morgan/bin/system_test.scr[37]: tnsping: not found
/morgan/bin/system_test.scr[37]: test: argument expected


Here is the script, any ideas?

#!/bin/ksh
#
# SET GLOBAL VARIABLES
IP="10.10.28.55" # target ip
ADMIN="morgan@telephonics.com" # admin to send mail to
MYMSG_GD="/morgan/working/system_good.txt" # ouput for successful tests
MYMSG_BD="/morgan/working/system_bad.txt" # ouput for failed tests
DB="deltekcp griffon epay deltektc testcp" # database names
TEST_STR="OK" # SQL test string
PAR="u01 u02 u03 u04 u05 u06 rootvol" # partition names
SIZE="" # create empty var
#
#
# CHECK FOR PREVIOUS OUTPUT FILES
if [ -s $MYMSG_GD ] # Is there a file with a length greater than 0?
then # Yes,
> $MYMSG_GD # erase it.
fi
if [ -s $MYMSG_BD ] # Is there a file with a length greater than 0?
then # Yes,
> $MYMSG_BD # erase it.
fi
#
# PING TEST
ping -c 2 $IP > /dev/null # ping target with a count of 2
if [ $? != 0 ] ; then # successful?
echo "couldn't ping enterprise box" > $MYMSG_BD # No, echo message
else
echo "enterprise box is alive" > $MYMSG_GD # Yes, echo message
fi
#
#
#
# SQL DB TEST
#
for x in $DB ; do # Are the databases up?
if [ `tnsping $x | grep OK | nawk -F ' ' '{print $1}'` != $TEST_STR ] ; then
echo "$x : down" >> $MYMSG_BD # NO, echo message
else
echo "$x : up" >> $MYMSG_GD # Yes, echo message
fi
done


# DISK SPACE TEST
for y in $PAR ; do # Current capacity over 98%?
if [ `df -k | grep $y | awk '{print $5}' | nawk -F '%' '{print $1}'` -ge "98" ]; then
echo "$y warning!" >> $MYMSG_BD # Yes, echo
else
echo "$y is below threshold" >> $MYMSG_GD # No, echo
fi
done
#
# MAIL FAILED OUPUT TO ADMIN
if [ -s $MYMSG_BD ]; then
cat $MYMSG_BD | mail $ADMIN
fi
 
look at man su

your environment is not set. You can setup a special user with a customized profile, which runs each time you logon.

Makes life easier.
 
Make sure $PATH etc are all set up in the script to be the same as that of the interactive session. You might also consider using fully qualified pathnames for ping etc so that the PATH issue isn't so critical. Another alternative is to run it as the user from within cron:

<cron times etc> su - <user> -c "full pathname to script"

Do a keyword search (for cron) in this or any of the more common unix fora on Tek-Tips to see many other threads about this subject. It happens because cron runs in a very limited environment. Good luck.
 
Thanks guys, for a temporary fix i just put the absolute path for the commands ping and tnsping. So the "not found" errors went away but im still getting the error:

/morgan/bin/system_test.scr[37]: test: argument expected

any ideas? I'm not sure but I don't think it has to do with the environment not being able to find the test command.
 
Replace this:
if [ `tnsping $x | grep OK | nawk -F ' ' '{print $1}'` != $TEST_STR ]
By this:
if [ "`tnsping $x | grep OK | nawk -F ' ' '{print $1}'`" != $TEST_STR ]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for the help PHV but that still did not work.

Once I made that change I no longer get that "test: argument expected" error but that part of the script is no executing correctly anymore. The tnsping to the databases should come back successful and they are failing. This is what I have:

#!/bin/ksh
#
# SET GLOBAL VARIABLES
IP="10.10.28.55" # target ip
ADMIN="morgan@telephonics.com" # admin to send mail to
MYMSG_GD="/morgan/working/system_good.txt" # ouput for successful tests
MYMSG_BD="/morgan/working/system_bad.txt" # ouput for failed tests
DB="deltekcp griffon epay deltektc testcp" # database names
TEST_STR="OK" # SQL test string
PAR="u01 u02 u03 u04 u05 u06 rootvol"
...
...
...
for x in $DB ; do
if [ "`/u01/app/oracle/product/8.1.7/bin/tnsping $x | grep OK | nawk -F ' ' '{print $1}'`" != $TEST_STR ] ; then
echo "$x : down" >> $MYMSG_BD # NO, echo message
else
echo "$x : up" >> $MYMSG_GD # Yes, echo message
fi
done
...
...
...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top