Scheduling a command to run every 3 days through cron

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scheduling a command to run every 3 days through cron
# 1  
Old 08-18-2009
Java Scheduling a command to run every 3 days through cron


I have to schedule a command to run on every 3 days. Whether the below cron entry will work?

0 3 */3 * * command

Please help me out and thanks in advance!
# 2  
Old 08-18-2009
you wanna run it every third day or after 3 days??
i suggest you to go for day basis i mean 0 to sunday and next will be 3 wed and 6 will be sat....
# 3  
Old 08-18-2009
The problem with using DOW is that there are 7 days - plus sunday may not be day 0 depending on your locale. 7 does not divide evenly by 3.

If you literally want every third day try setting up a daily cron entry that checks for "thirdness"
$(date +%s)/86400

is the number of days since Jan 1 1970. # of days % 3 == 0 means it is a day divisible evenly by three.
This trick works for any weird number of days that don't track well as a DOW or a fixed day in the month.

[[ $(( ($(date +%s)/86400) % 3   )) -eq 0 ]] && /home/me/

Last edited by jim mcnamara; 08-18-2009 at 09:21 AM..
# 4  
Old 08-18-2009
I want to run every 3 days say like 1st, 4th, 7th, 10th, 13th ......

jim mcnamara,
I verified the man page for %s in date command and which is not available (for %S is avaiable). Is that `date +%s` throws the number of seconds from the begining of the calendar? or only for the current day. As you suggested i am going for the well proposed solution DOW with fixed values.

FYI, I am using Unix AIX 5 OS.

Thanks for your help!
# 5  
Old 08-18-2009

One approach from a daily cron, using flag files.

# Is this day 3? (When we want to run myscript).
if [ -f myscript_day2 ]
       # Run myscript on day 3
       # Remove flag file ready for next time
       rm myscript_day2
# Is this day2 ?
if [ -f myscript_day1 ]
      rm myscript_day1
      touch myscript_day2
# Create day 1 flag file
touch myscript_day1

Last edited by methyl; 08-18-2009 at 11:40 PM.. Reason: bad paste
# 6  
Old 08-19-2009

The AIX date command has a feature to produce an integer for day-of-year (same as GNU/Linux date):
#!/usr/bin/env bash

# @(#) s1       Demonstrate producing day of year as integer.

set +o nounset
echo "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) date
set -o nounset

echo " Results:"
echo " Day of year as integer: $(date +%j)"

exit 0

$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: AIX, 1, 000641284C00
GNU bash 3.00.16
date - ( /usr/bin/date Jan 14 2003 )

 Day of year as integer: 231

This would be a constantly updated source for a sequence that could be checked for being divisible by 3. See man date for details ... cheers, drl
# 7  
Old 08-19-2009
I like a self-scheduling at job for this purpose:
#!/bin/sh - thanks to era...
: your code here
echo "$0" "$@" | at now + 3 days

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cron job cannot run the command

Hi, I created this cron job for asterisk to send sms daily to a number #!/bin/sh #custom mod - send sms once a day, at 07:00. CRON_PATH="/etc/asterisk/gw/crontabs_root"; if ! grep 'gsm send sms' $CRON_PATH > /dev/null 2>&1 ;then echo "* 7 * * * asterisk -rx 'gsm send sms 1 7666... (4 Replies)
Discussion started by: jazzyzha
4 Replies

2. Red Hat

Scheduling cron job

Hi Everybody, I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval. Regards, Mastan (3 Replies)
Discussion started by: mastansaheb
3 Replies

3. Shell Programming and Scripting

Scheduling Cron Jobs on Business Days

Hello, is it possible to schedule cron jobs using business days instead of calendar days? I need to run several jobs on first and third business days of the month. I currently have this cron-tab entry which runs every week day at 5 AM. I need to schedule the same job on the 3rd Business day of the... (8 Replies)
Discussion started by: Pramodini Rode
8 Replies

4. UNIX for Dummies Questions & Answers

Need to run a command from cron

How can I run the following command from cron? tar -cvf /email_backup/email_bu_062110.tar /prod/email (2 Replies)
Discussion started by: nim73
2 Replies

5. UNIX for Dummies Questions & Answers

Cron job to run a command from another dir?

I would like to setup a cron job to run a command from another directory. What is the best way to do this? The cron file is in a directory and the script I want it to run is in another directory. I tried doing this in the cron file: /location/of/command/ But that did not work.... (2 Replies)
Discussion started by: Sepia
2 Replies

6. UNIX for Advanced & Expert Users

Scheduling bi-weekly through cron

Is there a way in AIX to schedule a script to run bi-weekly through cron? I have a script that needs to run every other Wednesday, and this is what I thought I had to enter in the crontab file: 00 08 * * 3/2 /home/user/user.script It didn't like that. It reports a syntax error. I'm almost... (5 Replies)
Discussion started by: LPT
5 Replies

7. UNIX for Dummies Questions & Answers

Understanding cron scheduling command

Below are two cron entries. what is the difference beteeen writing 20 and */20? how is "20 * * * *" different from "*/20 * * * *"? 1) 20 * * * * find /tmp/ -name "*.log.*" ! -name "*.gz" -mmin +1440 -exec gzip '{}' \; 2) */20 * * * * find /tmp/ -name "*.tmp.*" ! -name "*.gz" -mmin +1440... (6 Replies)
Discussion started by: niks
6 Replies

8. HP-UX

cron scheduling?

Hi all, i want a job to run first monday of every of month. (1 Reply)
Discussion started by: megh
1 Replies

9. UNIX for Dummies Questions & Answers

scheduling tasks with cron

hello there, i'm learning about task scheduling with cron and all seems hyper exciting, yeppie. But there is a prob: assume i have a script that needed to be executed at 7am everyday. I could do: vi mycron 00 7 * * * echo hi mother, i wanna be a script daddy. :wq crontab mycron how... (4 Replies)
Discussion started by: alikun
4 Replies

10. UNIX for Advanced & Expert Users

cron job scheduling

Hi, How can I configure cron file , to execute a script on evey alternate saturdays ? I am using AIX 5.0 machine Thanks in advance Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies
Login or Register to Ask a Question