Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?

Thanks

share|improve this question
    
Is it a PHP question or a unix cronjob question? –  powtac Nov 23 '09 at 17:34
    
sorry for php tag ! –  Ahmet vardar Nov 23 '09 at 17:35
    
RTFM, man 5 crontab in this case –  reinierpost Nov 23 '09 at 17:41
    
tired tired tired –  kolypto Nov 23 '09 at 23:52
add comment

migrated from stackoverflow.com Nov 23 '09 at 20:05

This question came from our site for professional and enthusiast programmers.

6 Answers

up vote 17 down vote accepted

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
share|improve this answer
1  
that looks ok i guess –  Ahmet vardar Nov 23 '09 at 17:42
    
can i type * instead of 0 ? –  Ahmet vardar Nov 23 '09 at 17:44
4  
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 '09 at 17:46
add comment

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.

share|improve this answer
add comment

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!

share|improve this answer
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 '09 at 17:37
    
@Joy: No it's not; 10 * 1 * * is 10 past the hour, every hour, on the first day of the month. –  womble Nov 23 '09 at 20:29
add comment

Something like:

0 0 1 * * command /directory/file.ext
share|improve this answer
    
what is that 'command' and the 1 is at the month of the year place! –  Murali Nov 23 '09 at 17:36
    
you can do whatever you want with a cron, 99% of my usage has been: {TIMESTAMPS} {PHP_PATH} {FILE_PATH} –  Andrew G. Johnson Nov 23 '09 at 19:12
    
@Murali: No it's not. –  womble Nov 23 '09 at 20:30
add comment

use following:

@monthly     /home/user/backup.sh
share|improve this answer
add comment

Check this out: Class: PHP Cron

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.