Variables are not getting exported while running the script in cronjob

Hi All

Some how, variables are not getting exported while running the script in cronjob. Variable value is coming blank. But the variables are geting the value when the same script I am running manually. Any idea why?

When running the script in cron-job

user@server:~$ crontab -l
00 22 * * * $HOME/crt-offline-chkpnt.sh

When running the script manually

user@server:~$ ./crt-offline-chkpnt.sh

Thanks a lot to all in advance
C Saha

actually the file and the o/p is like this

$ cat crt-offline-chkpnt.sh

P4_COUNTER=`p4 -u cm -P cmpswd counters | grep journal | awk '{print $3}'`
echo "$P4_COUNTER" >aa.log

$ ./crt-offline-chkpnt.sh
$ cat aa.log
1157

No output when I have it in cronjob :frowning:

Hi,

have you checked the aa.log file, whats going in it
and post your cron entry as well

Gaurav

SORRY for the typo error in my previous post.

Yes I saw aa.log, its coming blank when its running by cronjob

This is cron settings

When running the script in cron-job

user@server:~$ crontab -l
00 22 * * * $HOME/crt-offline-chkpnt.sh

you may want to consider using explicit paths instead of paths with variables in them. quite honestly, i've never seen variables used in a cron table before.

if anything, you may want to check to see if:

  1. your script is running at all (check your local mailbox for cron errors(

and

  1. put in the full path to your 'p4' command.

Also try including your profile in the script your are calling via cron

Yes exactly. Both of your suggession worked. Its fine now.

I suggest that you change the default SHELL that CRON uses ( /bin/sh ?). I would change it to the default SHELL that your script is written in. You need to perform a man on cron to find it though. ' just a thought!

Good Luck!