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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable in Script ignored by crontab 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
Hi everyone,

I wrote a nice little script.

If I run it from command line everything is fine.

If I put it into crontab it gets executed but won't give me the correct output.

I assume this is because of the variable $searchstring is being ignored because of some unknown reason ...

Here's the script:

day=$(date +%e)
yesterday=`expr $day - 1`
month=$(date +%m)
year=$(date +%Y)
searchstring=$(echo "$year$month$yesterday")

iaccess -q "select EXTPRIM, K1200, K1112 from TBSP where DOCDATE = $searchstring" -v LOW -f SQL |wc > /tmp/count_TBSP.out

-> I believe the error occurs in "DOCDATE = $searchstring" but I'm not sure about that.

What's wrong here ?
Why does crontab fail when I'm able to run the script directly from command line without any problems ?

Regards
Thomas
 
On a number of systems crontab runs entries under a bourne shell. Could it be that from the command line you are using ksh ? If so, it may be worth trying #!/bin/ksh at the start of the script
 
Thanks for the hint.

No luck with that ...
 
If it's running from a command line but not cron then the problem is nearly always to do with environment settings in .profile and /etc/profile

Try something like
Code:
0 3 * * * su - root -c /path/to/my/script
BTW, you do realise that your code won't work at the month boundaries?
If you want yesterday's date try PHV's FAQ faq80-4800

Ceci n'est pas une signature
Columb Healy
 
Great, that was it !

The .profile was indeed the key !

Thanks a lot !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top