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

awk's problem into crontab...

Status
Not open for further replies.

nymus

IS-IT--Management
Jul 6, 2005
16
CH
Could someone explain my problem?

I've the following script...
Code:
#! /bin/ksh
...
vmquery -m $MediaID | awk '
BEGIN {FS=": "
getline expdate <"ExpDate.txt"
}
 $1 ~ /media ID/ {MediaNumber = $NF}
...
 $1 ~ /number of mounts/ {
 "date +%Y"|getline YearToday
 Year4 = YearToday - 4 
 if ($NF > 2000)
 {
   if (expdate ~ "[0-9]\{2\}\/[0-9]\{2\}\/[0-9]\{4\}")
   {
     printf("\t %s \n\n","=case 1==================")                                   >>"/home/op/report.txt"
     printf("%-20s\t %s\t %s\n","Media Number",":",MediaNumber)                         >>"/home/op/report.txt"
...
When I start this program in shell, it is running whitout problem and I've got the result in the file /home/op/report.txt.
But when I start this program via crontab, it is running whitout problem BUT it doesn't create the /home/op/report.txt

What's the problem? what I should doing?
Best regards
 
Hi

I think it can not find the file ExpDate.txt to read the value used in the [tt]if[/tt] condition, so the [tt]printf[/tt] functions will not be executed at all. Try to specify full path like /home/op/ExpDate.txt .

Feherke.
 
Hi

I've tried with the full path : /home/op/ExpDate.txt but it doesn't made the /home/op/report.txt!

nymus
 
Hi

Check the environment variables when a script is runned from [tt]cron[/tt]. Is the PATH ok ?

vmquery is running properly from [tt]cron[/tt] ?

Try using full pathes also for /usr/bin/awk and the other executables.

Feherke.
 
Have you tried running it with ksh -x scriptname to debug?

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Hi

vmquery was not found in the PATH from cron!
Now, I'm defined the PATH and it's ok and running...
Thanks a lot

-nymus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top