set -x
# Set the Path of Environment file
ENV_FILE_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin
LOG_DIR=/opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/log
export ENV_FILE_DIR
export LOG_DIR
# Set Audit Environment
. ${ENV_FILE_DIR}/QDM.env
export LOGFILE=${LOG_DIR}/obj_`date +%Y%m%d`.log
:>${LOGFILE}
SVRNM=${QDM_CFG_DIR}/svrnames.dat
MAILING_LIST= xxxxxxxx@something.com
for line in $(</opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/cfg/svrnames.dat);
do
echo $line | read servername
export name=$servername
ssh ly228m@$name "ksh /export/home/ly228m/QDM_QA/bin/OBE_schedule.ksh" >> ${LOGFILE}
RC=$?
if [[ ${RC} -ne 0 ]] then
echo "\n ERROR- Executing the object script on $servername \n"
mailx -s "OBJECT SCRIPT FAILURE on $name" $MAILING_LIST
else
mailx -s "OBJECT SCRIPT SUCCESS $name" ${MAILING_LIST}
fi
done < $SVRNM
for line in $(</opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/cfg/svrnames1.dat);
do
echo $line | read servername
export name=$servername
ssh ly228m@$name "ksh /home/ly228m/QDM_QA/bin/OBE_schedule.ksh" >> ${LOGFILE}
RC=$?
if [[ ${RC} -ne 0 ]] then
echo "\n ERROR- Executing the object script on $servername \n"
mailx -s "OBJECT SCRIPT FAILURE on $name" $MAILING_LIST
else
mailx -s "OBJECT SCRIPT SUCCESS $name" ${MAILING_LIST}
fi
done < $SVRNM
exit
which will connect and run another script on 15 servers and get the flat files genrated and transferred. It works perfectly when run manually, however it does not work when scheduled to run through crontab.
Please help me out with this issue.
Note: the most weird thign about this there are n number of scripts which are scheduled and works perfectly except for this script
for line in $(</opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/cfg/svrnames.dat);
do
...
...
done < $SVRNM
replace the loop by while
while read line
do
...
...
..
done < $SVRNM
replace these two lines by one line
echo $line | read servername
export name=$servername
to
name=$line
replace another for loop also.
Did u set the correct time and format (in the cron entry) and checked the execution ?
Hi,
I actually think we are deviating from the real issue. The issue is not with how the script is running rather it is with why it is not running only on crontab
I have tried the while loop, and preferred the for loop as it uses ssh to connect to a remote server, runs a script an generate files that has to be back on the remote server.
It has to repeat this like for 15 servers, the servers have varied root directory path, based on the root directory path on the servers i have two list files.
---------- Post updated at 02:55 PM ---------- Previous update was at 02:54 PM ----------
I am just inquisitive, does the ssh play a part with the crontab??
Any errors from the script will be in unix mail for the owner of the cron.
What Operating System and version are you runnning?
When running from the command line, what Shell are you running?
echo $SHELL
If you are actually running "ksh", there appear to be syntax errors in the script.
e.g.
MAILING_LIST= xxxxxxxx@something.com
Further:
The "ssh" command lines need the "-n" parameter in this context. This is very important with ksh.
In all the scripts it would reduce the complexity if you have a Shebang line at the start of each script and stop invoking "ksh scriptname".
Further:
I think that these "mailx" commands will hang waiting for keyboard input.