bkreynolds48
asked on
Shell script works when executed from command line but not when using at or cron
I am adding to an existing backup to tape script to resolve an error that occurs about once a month.
If I execute this script from the command line it works fine but when using at or cron it does not work.
Here is a tail -20 of the logfile I am reading from the script
========================== ========== ===
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9179.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9181.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9183.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9184.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9189.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9187.arc.Z
/data6/CNSPROD/arch/arch_C NSPROD_1_4 9191.arc.Z
/data6/CNSPROD/arch/
/data6/CNSPROD/
/data6/
/data7/
/
save: / 92 GB 03:21:33 137 files
Unmounted device: /dev/rmt/0n
End: 12/11/06 16:26
Unloading tape...
Error 117: Drive comm
Moving tape from slot 82 to slot 12...
Error 18: Source inside drive
========================== ========== ===
here is the new part of the script.
I cut the end of the script out for testing.
========================== ========== ===
########################## ########## ########## ########## ##########
# set -xv
#!/bin/ksh
#
DBA1='bkreynolds48@yahoo.c om';export DBA1
PATH=$PATH:/usr/bin:/usr/s bin/:/sbin :/bin:/usr /opt/netwo rker/bin; export PATH
#
LOGFILE=/data7/nsr/logs/su nday_cold_ backup.111 206; export LOGFILE
LG=/data7/nsr/lg; export LG
TP=`date "+%m-%d-%y"`;export TP
#
########################## ########## ########## ########## ##########
#
if [[ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ]];
then
tail -2 $LOGFILE | /usr/bin/mailx -s "Tape ERRORS" $DBA1 >$LG 2>&1
/usr/bin/touch /data7/nsr/verified_TPerro rs.$TP
echo TPerrors >>$LG 2>&1
/usr/bin/mailx -s "this is a test" $DBA1 <$LG >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_2NDtry .$TP
echo 2NDtry >>$LG 2>&1
tail -2 $LOGFILE | /usr/bin/mailx -s "Tape ERRORS" $DBA1 >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_TPerro rs.$TP
/usr/bin/mailx -s "this is a test 2- RETRY" $DBA1 <$LG >>$LG 2>&1
#
else
tail -5 $LOGFILE | /usr/bin/mailx -s "Cold Backup " $DBA1 >>$LG 2>&1
echo NOerror >>$LG 2>&1
/usr/bin/mailx -s "this is a test 3" $DBA1 <$LG >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_backup .$TP
fi
#
#
####################### End of Script ########################## #######
If I execute this script from the command line it works fine but when using at or cron it does not work.
Here is a tail -20 of the logfile I am reading from the script
==========================
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/arch_C
/data6/CNSPROD/arch/
/data6/CNSPROD/
/data6/
/data7/
/
save: / 92 GB 03:21:33 137 files
Unmounted device: /dev/rmt/0n
End: 12/11/06 16:26
Unloading tape...
Error 117: Drive comm
Moving tape from slot 82 to slot 12...
Error 18: Source inside drive
==========================
here is the new part of the script.
I cut the end of the script out for testing.
==========================
##########################
# set -xv
#!/bin/ksh
#
DBA1='bkreynolds48@yahoo.c
PATH=$PATH:/usr/bin:/usr/s
#
LOGFILE=/data7/nsr/logs/su
LG=/data7/nsr/lg; export LG
TP=`date "+%m-%d-%y"`;export TP
#
##########################
#
if [[ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ]];
then
tail -2 $LOGFILE | /usr/bin/mailx -s "Tape ERRORS" $DBA1 >$LG 2>&1
/usr/bin/touch /data7/nsr/verified_TPerro
echo TPerrors >>$LG 2>&1
/usr/bin/mailx -s "this is a test" $DBA1 <$LG >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_2NDtry
echo 2NDtry >>$LG 2>&1
tail -2 $LOGFILE | /usr/bin/mailx -s "Tape ERRORS" $DBA1 >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_TPerro
/usr/bin/mailx -s "this is a test 2- RETRY" $DBA1 <$LG >>$LG 2>&1
#
else
tail -5 $LOGFILE | /usr/bin/mailx -s "Cold Backup " $DBA1 >>$LG 2>&1
echo NOerror >>$LG 2>&1
/usr/bin/mailx -s "this is a test 3" $DBA1 <$LG >>$LG 2>&1
/usr/bin/touch /data7/nsr/verified_backup
fi
#
#
####################### End of Script ##########################
You haven't defined what "does not work" means.
Do you not get an email?
Are the wrong results sent?
Do you get any relevant error messages?
Do you not get an email?
Are the wrong results sent?
Do you get any relevant error messages?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What does not work from cron or at is that the script falls through to "NOerror" when it should see the tape error 18
I have tried using both "sh" and "ksh" shells
If you look at the script above you will see that I already have set -xv in it
Yuzh the is the output from the "tmp 2>&1" file
/data7/nsr/bk.test: [[: not found
I have tried using both "sh" and "ksh" shells
If you look at the script above you will see that I already have set -xv in it
Yuzh the is the output from the "tmp 2>&1" file
/data7/nsr/bk.test: [[: not found
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another point - albeit minor - is that when you're using Korn shell, you can export your variables directly, i.e.
DBA1='bkreynolds48@yahoo.c om';export DBA1
becomes
export DBA1='bkreynolds48@yahoo.c om'
DBA1='bkreynolds48@yahoo.c
becomes
export DBA1='bkreynolds48@yahoo.c
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I put the set command after the
#!/bin/ksh
but still have the same results........
/data7/nsr/bk.test: [[: not found
Thanks
Bev
#!/bin/ksh
but still have the same results........
/data7/nsr/bk.test: [[: not found
Thanks
Bev
ASKER
I changed
if [[ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ]];
to
if [ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ];
and it worked.
Thanks
if [[ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ]];
to
if [ "`tail -1 $LOGFILE`" = "Error 18: Source inside drive " ];
and it worked.
Thanks
Did you ensure
#!/bin/ksh
was the *very* first line?
In your original code, you had
########################## ####
as the first line, so if you didn't remove that, that will explain why it was still running under /bin/sh
#!/bin/ksh
was the *very* first line?
In your original code, you had
##########################
as the first line, so if you didn't remove that, that will explain why it was still running under /bin/sh
Who is the owner of cron job? Does that user get an email when the cron job completes/fails?