Particular script not running through crontab

Hi,
I have created the below script,

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.

30 00 * * * ksh /opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin/new_both.ksh

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 :frowning:

what you logfile says ?

post your code in [code] tag. (easy for read)

hi itkamaraj,
thanks for the info on the code tag. The script jus does not work as such. There are no files created :frowning:

check the cron logs

 
/var/log/cron*

there is nothing like that as well :frowning:

what is the use of this line (it is wrong) ?

 
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 ?

just redirect the output to tmp file and see

30 00 * * * ksh /opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/bin/new_both.ksh 1>/tmp/otuput 2>&1

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 :slight_smile:
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??

it will work

did u redirect the stdout and stderr to log file ?( as i mentioned in the above post)

1>/tmp/otuput 2>&1

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.

As a minimum, try:

echo ""|mailx -s "OBJECT SCRIPT FAILURE on $name" $MAILING_LIST
echo ""|mailx -s "OBJECT SCRIPT SUCCESS $name" ${MAILING_LIST}

The script do-done loops appears to have two conflicting inputs! For example:

You probably mean:

for servername in $(</opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/cfg/svrnames.dat)
do
export name=$servername
done

And

for line in $(</opt/app/p1trp1c1/sybase/ecdwqdm/xrbid/QDM_Prod/cfg/svrnames1.dat)
do
export name=$servername
done