Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

Cron runs script on Sunday when it is not supposed to

I have a cron entry to run a backup - it should not run on Sunday so I have "1-6" which should only run Monday through Saturday but it runs on Sunday as well.  Can anyone tell me what I have wrong here?

Thanks!

00 15 1-30 * 1-6 /data7/nsr/bckhot.sh
0
bkreynolds48
Asked:
bkreynolds48
  • 2
  • 2
  • 2
1 Solution
 
ahoffmannCommented:
please check which TZ is used for that user when it runs cron, also check TZ for root
0
 
bkreynolds48Author Commented:
The timezone is GMT
0
 
tfewsterCommented:
00 15 1-30 * 1-6
If day-of-month and day-of-week are specified, cron treats this as an OR, so if either condition matches, the job will run.

A way to prevent this would to be to run the cron job every day-of-month (except the 31st, which you've excluded for some reason?) and then put something like this in the backup script:
if [ `date +%a` = "Sun" ]
  echo "Sunday - skip backup"
  exit 0
fi

Though I confess I don't see why you would exclude the 31st of the month - Why not just specify day-of-week 1-6 and replace day-of-month with *? (that's the exception to the OR rule)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ahoffmannCommented:
tfewster, good eyes!
that's the parts of crontab's man page someone would read but forget thinking about it ...
0
 
bkreynolds48Author Commented:
I am skipping the "31st" because my tape library has only 30 tapes and I pull the tape by the day number and when the 31st comes I pull tape 15.

I will try you suggestion:

if [ `date +%a` = "Sun" ]
  echo "Sunday - skip backup"
  exit 0
fi

and see if this works for this coming Sunday.  
Will let you know on Monday.

Thanks
0
 
tfewsterCommented:
Ah, I see now!  In which case,
00 15 * * 1-6 /data7/nsr/bckhot.sh
will work fine and will use a maximum of 27 tape slots (look at the calendar for May 2006).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now