setting up crontabs

Discussion in 'Technical' started by cruz, Sep 10, 2007.

  1. cruz

    cruz New Member

    I have to setup 4 crontabs to run 4 scripts every hour. Is this the corect way to set up one of the scripts?
    HTML:
     crontab 0 * * * * /var/www/web4/web/cronjobs/delete_cache_files.php
     
  2. sjau

    sjau Local Meanie Moderator

    if you want to run php files by cron install the phpX-cli package and then I think the correct syntax is:
    Code:
    0 * * * * php -f /var/www/web4/web/cronjobs/delete_cache_files.php
    
    and if you don't want any feedback:
    Code:
    0 * * * * php -f /var/www/web4/web/cronjobs/delete_cache_files.php >/dev/null 2>&1
    
    and actually I would add crons like this:

    (1) create a text file "cron.txt"

    (2) edit it to add the crontabs:
    Code:
    0 * * * * php -f /var/www/web4/web/cronjobs/delete_cache_files.php >/dev/null 2>&1
    15 * * * * php -f /var/www/web4/web/cronjobs/script2.php >/dev/null 2>&1
    30 * * * * php -f /var/www/web4/web/cronjobs/script3.php >/dev/null 2>&1
    45 * * * * php -f /var/www/web4/web/cronjobs/script4.php >/dev/null 2>&1
    
    Or if it's the same script running every 15 min:

    Code:
    0,15,30,45 * * * * php -f /var/www/web4/web/cronjobs/delete_cache_files.php >/dev/null 2>&1
    
    (3) Save and exit the file

    (4) Run this command:
    Code:
    crontab /path/to/cron.txt
    
    (5) Check if it was added:
    Code:
    crontab -l
    
    I think managing cron with such a text file is simpler.
     
  3. cruz

    cruz New Member

    thanks for the crontab help

    That was nice and easy. I createdd the cron.txt and added the strings in there and then ran crontab /path/to/cron.txt. will they now run every hour around the clock?
    HTML:
    0 * * * * php -f /var/www/web4/web/cronjobs/delete_cache_files.php >/dev/null 2>&1
    0 * * * * php -f /var/www/web4/web/cronjobs/speeddater_email.php >/dev/nul 2>&1
    0 * * * * php -f /var/www/web4/web/cronjobs/mship_expiry_reminder_mail.php >/dev/null 2>&1
    0 * * * * php -f /var/www/web4/web/cronjobs/mymatches_email.php >/dev/null 2>&1
     
  4. falko

    falko Super Moderator Howtoforge Staff

    Yes, every full hour. :)
     
  5. cruz

    cruz New Member

    great

    thanks for the help.:)
     
  6. sjau

    sjau Local Meanie Moderator

    does it work?
     
  7. cruz

    cruz New Member

    great

    Yes it worked great. I created the cron file and it is working. I can see them when I run the command crontab -l. dose that mean they are running if I can see them? can I add cronjobs to this file and they will be ran as well?
     
    Last edited: Sep 12, 2007
  8. sjau

    sjau Local Meanie Moderator

    well, you could have sent yourself an email with the output of the cronjobs...

    if you want to add more crons, just edit the cron file and then do again:

    Code:
    crontab cron.txt
    
    to actualize it.
     
  9. bschultz

    bschultz Member

    Can anyone tell me where the CROn error log is? I'm on Debian, and can't find it in /var/log.

    Thanks.
     
  10. sjau

    sjau Local Meanie Moderator

    should be in syslog...
     
  11. bschultz

    bschultz Member

    I didn't see any errors, but the cron isn't working...I'll keep digging.
     
  12. bschultz

    bschultz Member

    Still didn't find the error in the logs anywhere, but did get an email that the permissions were wrong! Rookie mistake!
     

Share This Page