0

I have a cronjob that runs every saturday at 4am like: 0 4 * * 6 /var/lib/backup_weekly.sh >> /var/log/backup_weekly.log 2>&1

Is there a way to run a different script (backup_monthly.sh) at 4am the first saturday of every month? without running the script above (backup_weekly.sh)?

andresg3
  • 343
  • 2
  • 6
  • 20
  • you could run it on the same date (such as the 1st) of every month but to do what you want you'd probably need to add extra logic into your script (backup_weekly.sh) to determine whether it's the first saturday or not, and hence whether to do its thing or not. – Joe T Aug 28 '14 at 17:48

3 Answers3

0

I believe you would just add another line to the crontab and put the script you want to run and the specific date and time. Also here is a link for cron jobs in Unbuntu not sure what flavor your running but i know it works in Debian 4.6 (Squeeze)

Egregory
  • 218
  • 2
  • 9
0

Run the script every Saturday, and add to the script:

(( $(date +%w) < 7 )) || exit
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

You can the set the cron by:

0 4 1-7 * * [ date +\%u = 6 ] && /path/script

or else

0 4 1-7 * 6 /var/lib/backup_weekly.sh >> /var/log/backup_weekly.log 2>&1

Shirchabayshan
  • 181
  • 1
  • 2
  • 11
  • 0 4 1-7 * 6 means β€œAt 10:00 on every day-of-month from 1 through 7 and on Saturday" it does not work because this is executed every 1,2,3,4,5,6,7 of every month and every Saturday – alvaro nortes Apr 05 '19 at 08:52