Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem running script from CRON 1

Status
Not open for further replies.

tjv

IS-IT--Management
Sep 19, 2001
100
US
I am having problems running this script from cron. If I run it standalone I do not have any issues.
Code:
#!/bin/ksh
log_file=job_run.log
tail -1 $log_file | read l_year l_dayofyear l_restofit
cd /usr/users/twigguy
date +"%Y %j" | read t_year t_dayofyear
let "day_laped=($t_year - $l_year) * 365 + $t_dayofyear - $l_dayofyear"
echo $l_year $l_dayofyear $t_year $t_dayofyear $day_laped > gpg.log
echo "start"
if [[ $day_laped -gt 12 ]]
then
   cd /usr/users/twigguy
   /usr/users/twigguy/thruwaygpg.sh 1>  /usr/users/twigguy/gpg.log 2> /usr/users/twigguy/gpgsys.log
   date +"%Y %j %m %d %a %H:%M" >> $log_file
   mailx -s "Log Data" pgp_report < gpg.log
else
   echo do nothing >> gpg.log
echo "finish"
fi

I get an error that says "let cannot be found"

Thanks for any help
 
Check the value of your $PATH variable (echo $PATH) when you run the script interactivley, and include the same value at the beginning of your script, ie:

export PATH=<your path>

This is because cron runs in a very limited environment.
 
Ok I changed it to this

Code:
#!/bin/ksh
PATH=/sbin:/usr/sbin:/usr/bin:/usr/ccs/bin:/usr/bin/X11:/usr/local:/usr/local/bin:/usr/users/twigguy:/usr/users/twigguy/bin:/u
sr/bin:.:. ; export PATH
log_file=job_run.log
tail -1 $log_file | read l_year l_dayofyear l_restofit
date +"%Y %j" | read t_year t_dayofyear
let "day_laped=($t_year - $l_year) * 365 + $t_dayofyear - $l_dayofyear"
echo $l_year $l_dayofyear $t_year $t_dayofyear $day_laped > gpg.log
echo "day laped  " $day_laped >> dave
if [[ $day_laped -gt 12 ]]
 then
   thruwaygpg.sh 1> gpg.log 2> gpgsys.log
   date +"%Y %j %m %d %a %H:%M" >> $log_file
   date +"%Y %j %m %d %a %H:%M" >> dave
#  mailx -s "Log Data" pgp_report < gpg.log
 else
   echo "do nothing" >> gpg.log
fi

But am still getting the same error. I tried export PATH=<your path> but it gave a different error so I tried putting the export PATH at the end.
 
It isn't a problem with the path, "let" is a ksh builtin.

You should make sure the script is actually being run with the correct ksh. Do you have more than one ksh on your system? Can you echo the $SHELL in the script?
 
Not sure how to call the SHELL in the script.
 
Can you post the line in the crontab ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
crontab shows

13 11 * * * /usr/users/twigguy/ThruwayStart.sh

I change the start time to test it.
 
You may try this:
13 11 * * * exec /bin/ksh /usr/users/twigguy/ThruwayStart.sh

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That worked PHV Thanks.
13 11 * * * exec /bin/ksh /usr/users/twigguy/ThruwayStart.sh

I had also wrote another script that calls ThruwayStart.sh with ksh like this.

ksh ThruwayStart.sh

I put that in cron and it worked as well but I like you way better.

Thanks
 
It's interesting that your #!/bin/ksh wasn't working. There aren't any blank lines or spaces in there are there?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top