If you need to run scripts on specific weeks on a UNIX machine, then there is a easy way to determine this.
Based on this article’s date, we are currently on week 43 of 2013. To get the week number we just use the date command with the +%V
format option. The week numbers will be in the range from 1 to 53.
1 2 3 4 |
# date Sat, Oct 26, 2013 4:07:20 PM # date +%V 43 |
The week number is derived based on ISO 8601 standard.
Note that the date command supports another week number format – +%W
. This prints week numbers from 0 to 53 and this might not be what you are looking for.
1 2 3 4 |
# date Sat, Oct 26, 2013 4:15:30 PM # date +%V 42 |
The following code snippet can be used to run your stuff for a specific week in a shell script.
1 2 3 4 5 6 7 |
week=$(date +%V) # exit if we are not running on the required week 43 [ $week != 43 ] && exit 0 # if we are here, we are in the required week, do our stuff echo do our stuff |