mikekwok
asked on
Sheel script generating all weekday of previous month
I want to generate all weekday of previous month and output it to a text file using shell script.
For example, current month is July 2006 . after running the script, it will output a file called "date.txt" which contains :
01-06-2006
02-06-2006
05-06-2006
07-06-2006
.......
.......
30-06-2006
Pls help.
For example, current month is July 2006 . after running the script, it will output a file called "date.txt" which contains :
01-06-2006
02-06-2006
05-06-2006
07-06-2006
.......
.......
30-06-2006
Pls help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Where did you put the awk script, and do you refer to it by its absolute path in gen_weekday.sh? Just to be certain that there's no problem with the version of cal on your path, what do you get when you run the command:
cal 7 2006
Does the output look exactly like this?
July 2006
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
(note that this displays with a proportional font - the "1" should align under Sa with a fixed-width font.)
cal 7 2006
Does the output look exactly like this?
July 2006
Su Mo Tu We Th Fr Sa
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
(note that this displays with a proportional font - the "1" should align under Sa with a fixed-width font.)
ASKER
Hello bpmurray,
Sorry for the late reply.The output look exactly like this. But when I try to schedule it to run in the gen_weekday.sh in the crontab. The file cannot be generated. the output is what I mentioned in 07/25/2006 03:02AM PDT. Do you have any suggestion to fix the problem?
Sorry for the late reply.The output look exactly like this. But when I try to schedule it to run in the gen_weekday.sh in the crontab. The file cannot be generated. the output is what I mentioned in 07/25/2006 03:02AM PDT. Do you have any suggestion to fix the problem?
Just looked again at this, and the error message is an indication as to the problem - "awk: can't open 6". It looks like you're missing a "-" in the call to awk:
awk -f formatit.awk - $MON $YEAR
There should be a "-" surrounded by spaces, between ".awk" and "$MON". Can you confirm that this is the case?
awk -f formatit.awk - $MON $YEAR
There should be a "-" surrounded by spaces, between ".awk" and "$MON". Can you confirm that this is the case?
ASKER
58 17 25 07 * /aaa/home/scripts/gen_week
The weekday file is as follow:
awk: can't open 6
record number 6
1--
2--
5--
6--
7--
8--
9--
12--
13--
14--
15--
16--
19--
20--
21--
22--
23--
26--
27--
28--
29--
30--
Please help. Thanks,