LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Confused with cron (https://www.linuxquestions.org/questions/linux-server-73/confused-with-cron-875603/)

dinakumar12 04-18-2011 05:52 AM

Confused with cron
 
Hi all,


I have a cron job like this.

04 07 17 04 02 sh -x myscript

this means the file myscript should be executed when the server date comes to Apr 17 on Tuesday at 07 04 am.

But the file myscript runs on every tuesday of April month. Whats wrong with cron i am very confused. Your suggestions please.

Thanks&regards,
Dinesh.

jhcaiced 04-18-2011 06:07 AM

Hi,

Try reading the man page for the cron file format

man 5 crontab

The format is:

minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)

Best regards,

dinakumar12 04-18-2011 06:14 AM

hi,

Thanks i did that, But no improvement in my problem.

michaelk 04-18-2011 06:49 AM

FYI
Quote:

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, are
not *), 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.

dinakumar12 04-18-2011 08:58 AM

Hi michaelk,

Thanks for your reply.

``30 4 1,15 * 5'' from your example.

The command should run only when the date 1st and 15th of the month comes on friday. Is that possible.

michaelk 04-18-2011 09:27 AM

FYI that was a quote from the man pages...
If you want to run a job on a particular day / day of the week then you need something like the following.

04 07 1,15 * * [ "$(date '+\%a')" == "Fri" ] && /path/to/your/job.sh

dinakumar12 04-19-2011 07:13 AM

Thanks michaelk,

it works

I used

04 07 1,15 04 * [ "$(date '+\%w')" == "5" ] && /path/to/your/job.sh

This in cron to execute my job only on 1st and 15th date of April and that too only when it falls on friday.


All times are GMT -5. The time now is 11:23 AM.