|
|||||||||
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
unix and linux commands - unix shell scripting |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Can cron run a script on the 4th Saturday of the month, every month? I don't believe it can.
Here's what I have so far: 30 5 24-31 * 6 <command> |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
The syntax you show really should work, but it doesn't. It will run your script on each day of 24 through 31 and on each Saturday. This interpretation of the cron fields arose in System V and everyone who had right conformed.
Your math is off though. The 4th Saturday must occur on the 22 through the 28. Try this: 30 5 * * 6 [ `date +%e` -gt 21 -a `date +%e` -lt 29 ] && <command> |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
I did as you suggested but get this error:
sh: test: 0403-021 A ] character is missing. Here is my syntax (modified for testing today): 57 13 * * 4 [ `date +%e` -gt 8 -a `date +%e` -lt 11 ] && mail -s "cron test" me@homer.com < /users/me/test.txt Any ideas? |
|
#4
|
||||
|
||||
|
I have actually put code in a crontab and I too am getting the same error. That is odd since we have some very similiar tests in working crontabs. I don't have time to dig into now, but I will soon. In the meantime you could write a script called week4 that returns 0 or 1 depend on the week. And then use
week4 && command This has actually exposed a very interesting problem. Right now I'm thinking that cron jobs are pumped through a proto file just like at jobs. |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
There seem to be two issues: first everything after a per cent sign is getting truncated. You would think that I would have encountered a cron command before that used a %, but I guess that this must be my first. Also the backtick expressions are not being evaluated.
The syntax that works for me is: * * * * * eval [ `date +\%e` -gt 8 -a `date +\%` -lt 11] && <command> This is ugly enough that some cool script is needed. I'll write one this weekend. |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Excuse my continuing monologue
Anything after a % is stripped off a cron command and is feed as standard input into the command. This is mentioned on crontab(1) manpage. SunOS even has an example on their manpage. |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Thanks. I will test and advise.
|
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User entry in both cron.allow and cron.deny | ksvaisakh | Solaris | 5 | 12-25-2009 01:39 PM |
| cron job starts new cron proccess | ron76 | Solaris | 3 | 05-12-2008 02:07 AM |
| CRON usage for CRON job | skyineyes | UNIX for Dummies Questions & Answers | 1 | 01-17-2008 10:17 AM |
| AIX and cron logs filtering ?: /etc/cronlog.conf, /var/adm/cron/log | Keith Johnson | AIX | 0 | 01-09-2008 08:32 PM |
| Cron : you are not authorized to use cron. Sorry. | tt155 | UNIX for Advanced & Expert Users | 1 | 07-06-2005 11:37 AM |
|
|