Unix/Linux Go Back    


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

Can cron do this?

UNIX for Advanced & Expert Users


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-08-2003   -   Original Discussion by captainzeb
captainzeb's Unix or Linux Image
captainzeb captainzeb is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 2 December 2003, 5:12 PM EST
Location: Canada
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Can cron do this?

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  
Old Unix and Linux 10-08-2003   -   Original Discussion by captainzeb
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 63
Thanked 471 Times in 271 Posts
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  
Old Unix and Linux 10-09-2003   -   Original Discussion by captainzeb
captainzeb's Unix or Linux Image
captainzeb captainzeb is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 2 December 2003, 5:12 PM EST
Location: Canada
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
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  
Old Unix and Linux 10-09-2003   -   Original Discussion by captainzeb
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 63
Thanked 471 Times in 271 Posts
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  
Old Unix and Linux 10-10-2003   -   Original Discussion by captainzeb
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 63
Thanked 471 Times in 271 Posts
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  
Old Unix and Linux 10-10-2003   -   Original Discussion by captainzeb
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 63
Thanked 471 Times in 271 Posts
Excuse my continuing monologue Linux

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  
Old Unix and Linux 10-10-2003   -   Original Discussion by captainzeb
captainzeb's Unix or Linux Image
captainzeb captainzeb is offline
Registered User
 
Join Date: Jul 2003
Last Activity: 2 December 2003, 5:12 PM EST
Location: Canada
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Bug

Thanks. I will test and advise.
Sponsored Links
Closed


Linux 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



All times are GMT -4. The time now is 03:31 AM.