111

There are fields on my server's control panel like this

Minute - Hour - Day of month - Month - Day of the week - Command

How can I create a cron job runs on first day of the month with this fields?

2
  • Just make a note for myself here: 0 0 1 * ? * [command]
    – Dika
    Oct 27, 2021 at 3:56
  • 1
    It is very poor form to close a non-duplicate question just because an answer may exist elsewhere. It is obviously not a duplicate.
    – mckenzm
    Apr 14, 2023 at 0:13

6 Answers 6

179

This will run the command foo at 12:00AM on the first of every month

0 0 1 * * /usr/bin/foo

This article describes the various fields, look to the bottom of the page: http://en.wikipedia.org/wiki/Cron

To add this to your cron file, just use the command

crontab -e
6
  • 3
    that looks ok i guess
    – Ahmet vardar
    Nov 23, 2009 at 17:42
  • 1
    can i type * instead of 0 ?
    – Ahmet vardar
    Nov 23, 2009 at 17:44
  • 17
    If you typed * instead of the first zero it would run every minute of the first day of the month, if you typed * for the second zero it would run every hour on the first day of the month. *'s for both would run every minute of every hour on that day.
    – rzrgenesys187
    Nov 23, 2009 at 17:46
  • According to that Wikipedia page, the third and fifth fields are treated as OR clauses of the run condition, and the right syntax should be 0 0 1 * ? though my Vixie cron on Ubuntu 14 LTS refuses them Sep 16, 2016 at 13:16
  • be careful when run crontab -e because it write the cron according to the current user than crontab command.
    – Francesco
    Mar 28, 2017 at 7:03
20

Will run /usr/bin/foo at 12:10am on the first day of the month.

10 0 1 * * /usr/bin/foo

Will run /usr/bin/foo at 3:10am on every day.

10 3 * * * /usr/bin/foo

See http://www.scrounge.org/linux/cron.html


updated the crons, it was a copy paste error, thanks Joy Dutta!

5
  • 1
    3:10am every day is 10 3 * * * /usr/bin/foo 12:10am on first day of month is 10 * 1 * * /usr/bin/foo
    – Joy Dutta
    Nov 23, 2009 at 17:37
  • 1
    @Joy: No it's not; 10 * 1 * * is 10 past the hour, every hour, on the first day of the month.
    – womble
    Nov 23, 2009 at 20:29
  • 1
    According to that Wikipedia page, the third and fifth fields are treated as OR clauses of the run condition, and the right syntax should be 0 0 1 * ?, though my Vixie cron on Ubuntu 14 LTS refuses them Sep 16, 2016 at 13:21
  • The link does not seem to exist anymore
    – 030
    Oct 10, 2016 at 12:16
  • @030 link works for me.
    – powtac
    Oct 10, 2016 at 16:45
15

use following:

@monthly     /home/user/backup.sh

more information:

2

Check for a directory on your server at /etc/cron.monthly. If the directory exists, odds are your system is set up to run any executables it finds in that folder on a monthly basis. Just drop your script (or symlink it) in /etc/cron.monthly. Also, make sure your script is executable.

0

Something like:

0 0 1 * * command /directory/file.ext
3
  • what is that 'command' and the 1 is at the month of the year place!
    – Murali
    Nov 23, 2009 at 17:36
  • you can do whatever you want with a cron, 99% of my usage has been: {TIMESTAMPS} {PHP_PATH} {FILE_PATH} Nov 23, 2009 at 19:12
  • 1
    @Murali: No it's not.
    – womble
    Nov 23, 2009 at 20:30
-1

Check this out: Class: PHP Cron

1
  • 2
    Note that this question was not about PHP
    – Pere
    Mar 8, 2017 at 15:51

Not the answer you're looking for? Browse other questions tagged .