Grass-hopper
asked on
Cron Errors
One of our user accounts has a cron job setup to run every 15 minutes. However, on completion of the cron job they are getting emailed the following:
/opt/bin/run_test_connecti on.sh
produced the following output:
/opt/bin/run_test_connecti on.sh[31]: cut: not found
/opt/bin/run_test_connecti on.sh[37]: sleep: not found
/opt/bin/run_test_connecti on.sh[40]: grep: not found
/opt/bin/run_test_connecti on.sh[40]: cat: not found
/opt/bin/run_test_connecti on.sh[40]: wc: not found
/opt/bin/run_test_connecti on.sh[41]: expr: not found
/opt/bin/run_test_connecti on.sh[42]: test: argument expected
/opt/bin/run_test_connecti on.sh[26]: cut: not found
/opt/bin/run_test_connecti on.sh[27]: cut: not found
/opt/bin/run_test_connecti on.sh[29]: test: argument expected
/opt/bin/run_test_connecti on.sh[26]: cut: not found
/opt/bin/run_test_connecti on.sh[27]: cut: not found
/opt/bin/run_test_connecti on.sh[29]: test: argument expected
/opt/bin/run_test_connecti on.sh[26]: cut: not found
/opt/bin/run_test_connecti on.sh[27]: cut: not found
/opt/bin/run_test_connecti on.sh[29]: test: argument expected
The user's crontab is as follows:
# Check Databases and Listener are running
00,15,30,45 08-18 * * 1-5 /opt/bin/run_test_connecti on.sh
00,15,30,45 08-18 * * 1-5 /opt/bin/run_lsnr_check.sh
When they run the script manually it works fine with no errors - it's only returning this when run from the cron.
Cheers.
/opt/bin/run_test_connecti
produced the following output:
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
/opt/bin/run_test_connecti
The user's crontab is as follows:
# Check Databases and Listener are running
00,15,30,45 08-18 * * 1-5 /opt/bin/run_test_connecti
00,15,30,45 08-18 * * 1-5 /opt/bin/run_lsnr_check.sh
When they run the script manually it works fine with no errors - it's only returning this when run from the cron.
Cheers.
ASKER
Body of Script:
=========
#!/bin/ksh
#:
# ************************** ********** ********** ********** ********** *********
# * File @(#): run_test_connection.sh *
# * Date : 06-MAY-2004 *
# * Version : 1.0.0.0 *
# * Author : PSG *
# * Purpose @(#): UNIX Environment administration for Oracle. *
# * *
# * This script checks connections to databases. Send email *
# * alert if connections not being accepted. *
# * *
# * Parameters : *
# ************************** ********** ********** ********** ********** *********
# * Change History *
# * *
# * Date Done By Vers Description *
# * --------- ---------------- ---- -------------------------- ---------- *
# ************************** ********** ********** ********** ********** *********
#
cd /opt/bin
for LNE in `cat /var/opt/oracle/oratab | grep -v '^#' | grep -v '*' | grep -v 'i
ds' `
do
DB=`echo ${LNE} | cut -f1 -d:`
AUTO_START=`echo ${LNE} | cut -f3 -d:`
if test $AUTO_START = "Y"
then
. /opt/bin/ora_${DB}.env
# Submit the Oracle task in the background
nohup /opt/bin/test_connection.s h > /tmp/check_$ORACLE_SID.ora 2>&1 &
# Wait for 30 seconds
sleep 30
# Check for ORA- errors
check_stat=`cat /tmp/check_$ORACLE_SID.ora | grep -i ORA- | wc -l`
oracle_num=`expr $check_stat`
if [ $oracle_num -gt 0 ]
then
cnt=`cat /tmp/check_$ORACLE_SID.ora | wc -l`
cp -p /tmp/check_$ORACLE_SID.ora /tmp/check_$ORACLE_SID.ora .wrk
lne=1
while [ $lne -le $cnt ]
do
head -1 /tmp/check_$ORACLE_SID.ora .wrk > /tmp/line
err_chk=`cat /tmp/line | grep -i ORA- | wc -l`
if [ $err_chk -gt 0 ]
then
ora_err=`cat /tmp/line | grep -i ORA- | cut -c5-9`
oerr ORA $ora_err >> /tmp/connect.err
echo "" >> /tmp/connect.err
echo "Log in as Oracle and run the Oracle Administration menu by typin
g runmenu.sh at the command prompt." >> /tmp/connect.err
echo "" >> /tmp/connect.err
echo "Select the $ORACLE_SID Database Administration Menu and selec
t Start $ORACLE_SID Database NORMAL option" >> /tmp/connect.err
fi
sed '1d' /tmp/check_$ORACLE_SID.ora .wrk > /tmp/check_$ORACLE_SID.ora .tmp
mv /tmp/check_$ORACLE_SID.ora .tmp /tmp/check_$ORACLE_SID.ora .wrk
lne=`expr $lne + 1`
done
else
rm /tmp/check_$ORACLE_SID.ora 2>/dev/null
fi
if [ -f /tmp/connect.err ]
then
#mailx -s "HIDDEN"< /tmp/connect.err
mailx -s "SERVER: WARNING - $ORACLE_SID not accepting connections" HIDDEN
< /tmp/connect.err
rm /tmp/connect.err 2>/dev/null
#rm /tmp/check_$ORACLE_SID.ora 2>/dev/null
#rm /tmp/line 2>/dev/null
#rm /tmp/check_$ORACLE_SID.ora .wrk 2>/dev/null
fi
fi
done
PATH
===
/usr/bin:.:/usr/sbin:/etc: /usr/ccs/b in:/usr/uc b:/usr/ucb lib:/usr/o penwin/bin :/app/orac le/product /live/8.1. 7:/app/ora cle/produc t/live/8.1 .7/bin:/ex port/home/ oracle:/ex port/home/ oracle/scr ipts:/expo rt/home/ss
=========
#!/bin/ksh
#:
# **************************
# * File @(#): run_test_connection.sh *
# * Date : 06-MAY-2004 *
# * Version : 1.0.0.0 *
# * Author : PSG *
# * Purpose @(#): UNIX Environment administration for Oracle. *
# * *
# * This script checks connections to databases. Send email *
# * alert if connections not being accepted. *
# * *
# * Parameters : *
# **************************
# * Change History *
# * *
# * Date Done By Vers Description *
# * --------- ---------------- ---- --------------------------
# **************************
#
cd /opt/bin
for LNE in `cat /var/opt/oracle/oratab | grep -v '^#' | grep -v '*' | grep -v 'i
ds' `
do
DB=`echo ${LNE} | cut -f1 -d:`
AUTO_START=`echo ${LNE} | cut -f3 -d:`
if test $AUTO_START = "Y"
then
. /opt/bin/ora_${DB}.env
# Submit the Oracle task in the background
nohup /opt/bin/test_connection.s
# Wait for 30 seconds
sleep 30
# Check for ORA- errors
check_stat=`cat /tmp/check_$ORACLE_SID.ora
oracle_num=`expr $check_stat`
if [ $oracle_num -gt 0 ]
then
cnt=`cat /tmp/check_$ORACLE_SID.ora
cp -p /tmp/check_$ORACLE_SID.ora
lne=1
while [ $lne -le $cnt ]
do
head -1 /tmp/check_$ORACLE_SID.ora
err_chk=`cat /tmp/line | grep -i ORA- | wc -l`
if [ $err_chk -gt 0 ]
then
ora_err=`cat /tmp/line | grep -i ORA- | cut -c5-9`
oerr ORA $ora_err >> /tmp/connect.err
echo "" >> /tmp/connect.err
echo "Log in as Oracle and run the Oracle Administration menu by typin
g runmenu.sh at the command prompt." >> /tmp/connect.err
echo "" >> /tmp/connect.err
echo "Select the $ORACLE_SID Database Administration Menu and selec
t Start $ORACLE_SID Database NORMAL option" >> /tmp/connect.err
fi
sed '1d' /tmp/check_$ORACLE_SID.ora
mv /tmp/check_$ORACLE_SID.ora
lne=`expr $lne + 1`
done
else
rm /tmp/check_$ORACLE_SID.ora
fi
if [ -f /tmp/connect.err ]
then
#mailx -s "HIDDEN"< /tmp/connect.err
mailx -s "SERVER: WARNING - $ORACLE_SID not accepting connections" HIDDEN
< /tmp/connect.err
rm /tmp/connect.err 2>/dev/null
#rm /tmp/check_$ORACLE_SID.ora
#rm /tmp/line 2>/dev/null
#rm /tmp/check_$ORACLE_SID.ora
fi
fi
done
PATH
===
/usr/bin:.:/usr/sbin:/etc:
I would suggest you try this
crontab -l > /tmp/cron
crontab -l > /tmp/cron_b (N.B Just as a backup of the original)
vi /tmp/cron
Edit the file so that it looks like this:
00,15,30,45 08-18 * * 1-5 /bin/sh -c '/opt/bin/run_test_connect ion.sh'
00,15,30,45 08-18 * * 1-5 /bin/sh -c '/opt/bin/run_lsnr_check.s h'
save the file {ESC}:wq!
crontab < /tmp/cron
This should give the cron the same environment as running it from a prompt.
Vince
crontab -l > /tmp/cron
crontab -l > /tmp/cron_b (N.B Just as a backup of the original)
vi /tmp/cron
Edit the file so that it looks like this:
00,15,30,45 08-18 * * 1-5 /bin/sh -c '/opt/bin/run_test_connect
00,15,30,45 08-18 * * 1-5 /bin/sh -c '/opt/bin/run_lsnr_check.s
save the file {ESC}:wq!
crontab < /tmp/cron
This should give the cron the same environment as running it from a prompt.
Vince
It is the ENV seting, the PATH setting for cron is in the /etc/default/cron
file.
man cron
man crontab
to learn more details.
You can modify the script to FULL path for commands, eg:
use "/usr/bin/cut" instead of "cut", OR defind PATH etc in the sctipt before
all the command. OR, "source" a ENV setting file (eg a login script):
#!/bin/ksh
. /path-to/.profile # a Dot SPACE then /path-to/.profile
# following by the script body
....
#End of script.
If you are 100% sure that the script works in the user (eg fred's) login
ENV, you can also use root's crontab to run the script as user fred, see
the example in:
http:Q_20651566.html#8745475
file.
man cron
man crontab
to learn more details.
You can modify the script to FULL path for commands, eg:
use "/usr/bin/cut" instead of "cut", OR defind PATH etc in the sctipt before
all the command. OR, "source" a ENV setting file (eg a login script):
#!/bin/ksh
. /path-to/.profile # a Dot SPACE then /path-to/.profile
# following by the script body
....
#End of script.
If you are 100% sure that the script works in the user (eg fred's) login
ENV, you can also use root's crontab to run the script as user fred, see
the example in:
http:Q_20651566.html#8745475
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers guys - I'll give your suggestions a try and get back to you to how it goes.
ASKER
Cheers for all your replies guys - its appreciated.
It turns out it was exactly what tfewster said about the ora_${DB}.env call overwriting the default PATH. When we traced it to the related script - thats exactly what it was doing and we were able to sort it.
It turns out it was exactly what tfewster said about the ora_${DB}.env call overwriting the default PATH. When we traced it to the related script - thats exactly what it was doing and we were able to sort it.
(i) The text in the shell script needs to be shown to us so please append this to the question
and
(ii) The result of echo $PATH
Thanks
Vince