please post the crontab line
try to use full path to all program in your crontab
Main Topics
Browse All TopicsI tried to run the following script in command prompt in UNIX , it works fine.
cal 8 2006 | grep -v "[A-Z]" | cut -c4-17 | awk -f /aaa/home/scripts/aaa_oli_
The output (1.txt) is as follow:
01/08/2006
02/08/2006
03/08/2006
04/08/2006
07/08/2006
08/08/2006
09/08/2006
10/08/2006
11/08/2006
14/08/2006
15/08/2006
16/08/2006
17/08/2006
18/08/2006
21/08/2006
22/08/2006
23/08/2006
24/08/2006
25/08/2006
28/08/2006
29/08/2006
30/08/2006
31/08/2006
However when i try to run it in crontab, the following output is generated:
awk: can't open 8
record number 6
01//
02//
03//
04//
07//
08//
09//
10//
11//
14//
15//
16//
17//
18//
21//
22//
23//
24//
25//
28//
29//
30//
31//
Please suggest a solution for solving the problem. Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>I can't omit the "8 2006" after formatit.awk in the script because it will generate the output with missnig the month and year.
Looks like 8 and 2006 are parameters for formatit.awk and not input file. In this case you need to modify your call to awk in something like the following:
awk -f /aaa/home/scripts/aaa_oli_
Replace "month" and "year" by the name of the variables you use in your script for the month and year.
> MON=ARGV[2]
what should this do?
awk has no ARGV, gawk has.
But if you want to pass parameters to the awk program itself (beside the text it should process), you better use gawk with its -v option.
As I suggested several times now: please use full path to awk. I guess that your cron uses tradtional AT&T awk while in your shell you use gawk (probably aliased or found in PATH first). Please correct me if I'm wrong.
Try the following:
cal 9 2006 | grep -v "[A-Z]" | cut -c4-17 | awk -v mon=9 -v year=2006 '{for (i=1;i<=NF;i++) printf "%02d/%02d/%d\n", $i, mon, year;}'
As ahoffmann as already suggested, you probably have different 'flavor' of awk (e.g. awk, nawk, gawk, ...) on your system and that's the reason why he suggest you to set the full path to awk. If you don't know which version you use, when you are connected in the shell simply issue a "which awk" command. This command will display the full path to awk.
For example:
$ which awk
/usr/bin/awk
$
Now that you know the full path to awk, just edit your crontab like this:
22 16 05 09 * cal 8 2006 | grep -v "[A-Z]" | cut -c4-17 | /usr/bin/awk -f /aaa/home/scripts/aaa_oli_
or
22 16 05 09 * cal 9 2006 | grep -v "[A-Z]" | cut -c4-17 | /usr/bin/awk -v mon=9 -v year=2006 '{for (i=1;i<=NF;i++) printf "%02d/%02d/%d\n", $i, mon, year;}' > /aaa/home/scripts/aaa_oli_
> ..and that's the reason why he suggest you to set the full path to awk.
It's one reason, another is that crontab has a very limited environment (including PATH), hence I suggest that *all* programs are used with full path.
Just to be more precise :)
BTW, /usr/bin/awk on non-Linux systems is most likely AT&T awk which has no -v.
A simple test is
awk -V
if you get an (bailing out ...) error it's old fashioned awk, if you get usage most likely gawk.
I still got error......
here is the script ....
the filename is called "gen_weekday.sh"
#!/bin/ksh
MON=`date '+%m'`
YEAR=`date '+%Y'`
if [ $MON -eq 1 ]
then
MON=12
YEAR=`expr $YEAR - 1`
else
MON=`expr $MON - 1`
fi
cal $MON $YEAR | grep -v "[A-Z]" | cut -c4-17 | awk -v mon=$MON -v year=$YEAR '{for (i=1;i<=NF;i++) printf "%02d/%02d/%d\n", $i, mon, year;}'
in crontab
11 17 08 09 * /aaa/home/scripts/gen_week
the date.txt contains the error:
awk: syntax error near line 1
awk: bailing out near line 1
Please suggest me how to solve the problem. Thanks.
Business Accounts
Answer for Membership
by: JulieBouillonPosted on 2006-09-05 at 01:37:18ID: 17454083
Could you try like this: valo_all/f ormatit.aw k - > /aaa/home/scripts/aaa_oli_ valo_all/1 .txt
cal 8 2006 | grep -v "[A-Z]" | cut -c4-17 | awk -f /aaa/home/scripts/aaa_oli_
I assume the parameters "8 2006" are not needed by your awk script. In fact if you specify "8 2006" the way you did, awk will try to open first the file - (which is the ouput of the pipe), then the file 8 and finally the file 2006.