Hello,
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!
Hello,
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!
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....
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/myscript.sh
vidyadhar85,
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!
One approach from a daily cron, using flag files.
# Is this day 3? (When we want to run myscript).
if [ -f myscript_day2 ]
then
# Run myscript on day 3
myscript
# Remove flag file ready for next time
rm myscript_day2
exit
fi
# Is this day2 ?
if [ -f myscript_day1 ]
then
rm myscript_day1
touch myscript_day2
exit
fi
# Create day 1 flag file
touch myscript_day1
Hi.
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.
echo
set +o nounset
LC_ALL=C ; LANG=C ; export LC_ALL LANG
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
echo " Results:"
echo " Day of year as integer: $(date +%j)"
exit 0
yielding:
$ ./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 )
Results:
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
I like a self-scheduling at job for this purpose:
#!/bin/sh - thanks to era...
: your code here
echo "$0" "$@" | at now + 3 days