AIX cron job is running everyday instead of on a particular day

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
# 1  
AIX cron job is running everyday instead of on a particular day


I was trying to run a script on a dev server using cron job. It supposed to run 3rd sunday of every month.
45 4 15-21 * 0 /home/user1/ >/dev/null 2>&1 # run this script 3rd sunday of every month

When I Schedule it on AIX server, It is running every day at 4:45 AM.
am I doing anything wrong ?

I am thinking to try below, please suggest.

45 4 15-21 * 7 /home/user1/ >/dev/null 2>&1 # run this script 3rd sunday of every month

But It is same as "0" for sunday.

How about below ?

45 4 15,16,17,18,19,20,21 * 0 /home/user1/ >/dev/null 2>&1 # run this script 3rd sunday of every month

Please suggest.


Last edited by Kumar7997; 09-17-2018 at 12:52 PM.. Reason: adding the code
# 2  
Yes, I fell over the some 20 years ago with the same result. It seems that cron does not make sure that all conditions for the day match, so you may find that it runs every day between 15th & 21st each month AND every Sunday.

You would think that what you have set up is perfectly sensible, but sadly the cron designers had other ideas.

I got round this by running a shell script everyday that decided if I was on the correct day and correct week, and if so then it progressed to run the script I really wanted. it is annoying and I sympathise, but that was my way round it.

From the crontab file manual (man 5 crontab) I get this:-
Note: The day of a commandís execution can be specified by two fields ó day of month, and day of week. If both fields are restricted (ie, arenít *), the command will be run when
either field matches the current time. For example,
"30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

I hope that this helps,
This User Gave Thanks to rbatte1 For This Post:
# 3  
That means cron treats the dom field and the dow field as OR.
To make an AND, you put one field into the crontab and make your script exit on the other condition. For example
45 4 * * 0 /home/user1/ >/dev/null 2>&1 # run this every sunday

And at the beginning of you put
# exit if day-of-month is not 15..21
dom=`date +%d`
[ $dom -ge 15 -a $dom -le 21 ] || exit
# the real script follows

Or, the other way round:
45 4 15-21 * * /home/user1/ >/dev/null 2>&1 # run this every day 15..21

And at the beginning of you put
# exit if today is not Sunday
dow=`date +%w`
[ $dow -eq 0 ] || exit
# the real script follows

Last edited by MadeInGermany; 09-17-2018 at 03:01 PM..
These 2 Users Gave Thanks to MadeInGermany For This Post:
# 4  
Thank you!
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #792
Difficulty: Easy
In mathematics and digital electronics, a binary number is a number expressed in the base-2 numeral system or binary numeral system.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CRON job still running?

Hi All, I am writing a script that will eventually be executed by a cron job every 15 minutes. I want to make sure that my logic/script doesn't get executed if a previous job is still running. What would be the best way to handle that scenario? I was thinking to make my script create a temporary... (1 Reply)
Discussion started by: rdogadin
1 Replies

2. Solaris

Cron job running even after cron is removed

Hi , I have removed a cron for particular user , but cron job seems to be running even after the cron entry is removed. The purpose of the cron was to sendmail to user ( it uses mailx utility ) I have restarted cron and sendmail service still user is getting mail alerts from the cron job. And... (4 Replies)
Discussion started by: chidori
4 Replies

3. UNIX for Advanced & Expert Users

Run A Job in Cron On A Specific Day Excluding Holidays

Hi, I want to run a job in cron on a specific date(say 25th of every month) excluding holidays. Can anyone provide some hints to do this? Thanks for any inputs. (1 Reply)
Discussion started by: sktkpl
1 Replies

4. Shell Programming and Scripting

Adding a cron job that will execute everyday at 14:50 hrs

Hi I want to execute a cron job everyday at 14:50 hrs. I have a script like this: TMP_FILE="/tmp/tmpcron.txt" RES=0 /usr/bin/crontab -l >> $TMP_FILE ADD_JOB="50 14 * * * /opt/mypath/" grep "" $TMP_FILE >> /dev/null JOB_NOT_EXIST=$? if test $JOB_NOT_EXIST... (2 Replies)
Discussion started by: saurabhkoar
2 Replies

5. Solaris

Cron job is not running

Hi, I have set up the crontab as follows. root@IDC4VASAPP07 # crontab -l 0-59 * * * * /var/tmp/ 0-59 * * * * date >> /var/tmp/log root@IDC4VASAPP07 # is as follows. root@IDC4VASAPP07 # cat #!/bin/bash dt1=$(perl -e 'use POSIX;print strftime... (10 Replies)
Discussion started by: SunilB2011
10 Replies

6. UNIX for Advanced & Expert Users

Autosys Job Running every 5th Day of Month

Hi, Is there a way to schedule a job in Autosys to run every 5th Day of Month without using custom calendar? Thanks. (1 Reply)
Discussion started by: vbhatnag
1 Replies

7. Shell Programming and Scripting

Cron job randomly once a day

I want to create a cron job randomly once a day for my site's registration. The responsible file for registrations is a config file and I need to change the contents twice on day (on and off) I know the way for random cron job for example */n * * * * /usr/local/bin/php... (6 Replies)
Discussion started by: lucker
6 Replies

8. UNIX for Dummies Questions & Answers

Cron job not running

Hi All, I am editing crontab using -e option to add a new job Below is the line 30 * * * * scriptpath This job is not executing every thirty minutes. I have checked, cron daemon is running. What did I miss? Can some one help? I am using cron shell..ksh (7 Replies)
Discussion started by: yabhi_22
7 Replies

9. UNIX for Advanced & Expert Users

cron job is not running

hi, i have the following line in the crontab 15 5 * * 6 /home/adw/ The problem is the cron job is not getting started automatically. But this was working til last week. now it is not working. what could be the problem. Any idea? (3 Replies)
Discussion started by: Suguna
3 Replies

10. HP-UX

Cron Job Not Running

Hi, I have a cron schedule like this 04,16,28,40,52 * * * * /nag/startProcessABatch (unix script) i want to add new lines in this file (like Logging), i just copy this file into a /tmp folder (for backup copy), and i have edited this file (added few lines of code for logging). ... (1 Reply)
Discussion started by: nag_sundaram
1 Replies

Featured Tech Videos