1838646 Members
2422 Online
110128 Solutions
New Discussion

Cron job problem

 
SOLVED
Go to solution
MKR_1
Frequent Advisor

Cron job problem

I have written a script which runs well in command prompt as root,but it gives a different o/p when scheduled in cron job.

The script redirects the o/p to a file and compares it with another file.It returns all ok if there are no difference else returns the difference.
When i run this in CLI as root its all ok but in cronjob it gives differences.Please advice
4 REPLIES 4
Sunny123_1
Esteemed Contributor

Re: Cron job problem

Hi

Post your crontab entry.

Regards
Sunny
Pete Randall
Outstanding Contributor
Solution

Re: Cron job problem

Usually when something runs fine from the command line but not in cron, the cause is cron's minimal environment. You need to use full path names for everything and define all your environment variables within your cron job.


Pete

Pete
MKR_1
Frequent Advisor

Re: Cron job problem

SCHD=/home/151001/sched.txt
KSCHD=/home/151001/sched-frm.txt
LOG=/home/151001/schd-chk.log
/opt/UniQ/Batch/programs/commands/liq -Owner batch -No_Prompt|grep -i stream01|grep -i new|awk '{print $3}' > $SCHD
diff $SCHD $KSCHD
RC=$?
if [ RC -eq 0 ]
then
echo "\nSchedules ok \n" >> $LOG
else
echo "\nCheck the following jobs in schedules\n" >> $MLOG
diff $SCHD $KSCHD >> $MLOG
fi

mailx -s "Checks-Schedule" 151001 <$LOG
rm $LOG
exit 0

When the script is executed by cronjob the file $SCHD is empty
MKR_1
Frequent Advisor

Re: Cron job problem

thanks