Issue calling scripts through CRON.

I have the following cron job in the crontab.

#! /bin/bash

25 15 * * 1-5 /export/home/svittala/scripts/scpt1.sh >/dev/null 2>&1.

The problem that I am facing is - the scpt1.sh can be executed manually. But, it is not executing through CRON. Not sure what's the issue. Any hints?. Thanks.

Satish

Not sure why you have the /bin in your message. Not normally part of a crontab. That would be the first line of your scpt1.sh file

Another thought on the difference in execution - you might not be in bash as your interactive shell. Thus, the commands might be running ok because the syntax is good for ksh (or whatever).
>echo $SHELL will tell you your interactive shell.

Also, not sure hy you had a . (period) at the end of your crontab instruction line -- perhaps you were merely ending a sentence as you typed. But, you probably don't want a period.

Otherwise, cut/paste the entire crontab file and the program that will not run.

I'd start with eliminating "/dev/null" from your vocabulary. Change that to "/tmp/scpt1.sh.out" instead and you will likely get your answer.

I think the answers to about 90% of our problems are in /dev/null...too bad it's a black hole!

Per Joe's suggestion, I removed the # bash entry on the first line and also removed the /dev/null and instead redirected the output to a tmp file.

Now, it creates a tmp file with 0 bytes and ofcourse the script did not trigger. This is my simple script:

===============================

#! /bin/bash
. $HOME/.profile

# Informatica Settings
#. /ga/applsw/informatica/server/set_informatica_env.sh
# File Areas
# INCOMING_DIR=/home/applusr/e290147/incoming/
# LOG_DIR=/home/applusr/e290147/log/
# INF_SESS_DIR=/ga/applsw/informatica/server/SessLogs/
PMCMD_DIR=/applsw/informatica/server/powercenter8.1.1/server/bin/
INF_USER=E290133
INF_PASS=etlguy
INF_FOLDER=dev_HHSC_EADW
INT_SERVICE=hhsc_uce_dev_int_svc
DOMAIN=hhsc_informatica_uce_dev

# Log Files
LOG_DATE=`date +"%m%d.%H%M"`
LOG_FILE=${LOG_DIR}scpt1.log.${LOG_DATE}

# Return Codes for pmcmd
RETCODE_PROD=0

echo "################################################################################"
echo ""
echo "EXECUTING INFORMATICA WORKFLOW........"
echo ""
echo "################################################################################"

${PMCMD_DIR}pmcmd startworkflow -sv ${INT_SERVICE} -d ${DOMAIN} -u ${INF_USER} -p ${INF_PASS} -f ${INF_FOLDER} -wait wf_s_test2

RETCODE_PROD=$?

if [ ${RETCODE_PROD} = 0 ]; then
echo "################################################################################"
echo ""
echo "SUCCESSFULLY EXECUTED INFORMATICA WORKFLOW........"
echo ""
echo "################################################################################"
echo "scpt1.ksh completed processing successfully at "`date +"%m%d.%H%M"`"\n" >> ${LOG_FILE}
exit 0
else
echo "scpt1.ksh FAILED at "`date +"%m%d.%H%M"`"\r" >> ${LOG_FILE}
exit 0

fi

I just modified my cron to something like this:

45 16 * * 1-5 ls -ltr > /export/home/svittala/scripts/scpt1.sh.out

and it looks like it executed perfectly. Not sure whats the issue when I try to call a script.

If I put something like this in the command prompt:

/export/home/svittala/scripts/scpt1.sh > /export/home/svittala/scripts/scpt1.sh.out

it executes fine. Thanks.

I don't think joeyg was saying to remove the #!/bin/bash from the start of your script. I think he was pointing out that cron executes everything from bourne shell with a very limited environment. For instance, I doubt that $HOME will be available to the script.

Just change the redirect but leave the #! path at the start. Alternatively, specify the shell you want to run in the cron commandline. Add a -x flag to the shell to get more information if you need it.