1

crontab was at one point running properly but one day after running it deleted its file in /var/spool/cron/crontabs

# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.DYqvRY/crontab installed on Thu Mar 17 14:50:32 2016)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

0 0 1 * *  /var/www/html/mail.php

0 0 16 * *  /var/www/html/mail.php

0 13 2 * * /var/www/html/mailcheck.php

0 13 17 * * /var/www/html/mailcheck.php

0 13 2 * * /var/www/html/mailcheckadmin.php

0 13 17 * * /var/www/html/mailcheckadmin.php

0 0 1 * *  /var/www/html/PaymentPeriod_Create.php

0 0 16 * *  /var/www/html/PaymentPeriod_Create.php

* * * * * /var/www/html/testsession.php  > /var/www/html/log

I am using # crontab -e to edit this file then when i'm done I press ^X Y ENTER is there any extra step that i am missing * * * * * /var/www/html/testsession.php > /var/www/html/log this should run every minute right?

3
  • This runs every minute: */1 * * * * /var/www/html/testsession.php > /var/www/html/log Commented Mar 17, 2016 at 15:06
  • @Daan I changed that line but still the script is not running Commented Mar 17, 2016 at 15:13
  • @Daan why */1 * * * * rather than * * * * *? Are they equivalent? I always use * * * * * to run something every minute Commented Mar 17, 2016 at 15:48

1 Answer 1

3

The syntax * * * * * /var/www/html/testsession.php > /var/www/html/log is valid.

Most likely since it is the final line in the crontab it is missing the newline. Cron requires a newline at the end of every entry; in other words your crontab must finish with an empty line.

From the "Diagnostics" section of man crontab:

cron requires that each entry in a crontab end in a newline character. If the last entry in a crontab is missing the newline, cron will consider the crontab (at least partially) broken and refuse to install it.

You may want to replace the > with a >> so that new content is appended to the log file rather than overwriting it every minute, ie * * * * * /var/www/html/testsession.php >> /var/www/html/log. This will still create the log file if it is not already present.

Your PHP file will also need the execute bit set and will need to start with #!/usr/bin/php (or the path to PHP on your system) on the first line. Alternatively you could replace the cron line with * * * * * /usr/bin/php /var/www/html/testsession.php >> /var/www/html/log to explicitly use the PHP interpreter to execute the script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.