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.

I have a folder in my live directory (/var/www), called cron. How do I configure the server to find this directory, in order to execute the files using a cron.

I need to run certain scripts at different intervals. e.g. 2-3 Files everyday, and 1-2 files every Wednesday.

What would I need to put in the crontab in order do the above? I've attempted to add * * * * * /var/www/email.php as a text, which should send me an email every minutes, but nothing comes through.

Am I doing something wrong?

share|improve this question
1  
Have you tried to see /var/log/syslog to check for error messages ? Do you have access to the server as root ? Maybe the cron service is not running... –  Feiticeir0 Aug 7 '11 at 15:46
    
It says it failed with exit status 2? –  user826855 Aug 7 '11 at 16:14
    
exit status 2 usually is ENOENT i.e. 'no such file or directory'. Cron probably wasn't able to read its file. –  bitwelder Aug 7 '11 at 19:02
add comment

2 Answers

try it this way:

* * * * * php -q /var/www/email.php

also make sure the file is executable as the user you run the cronjob as

share|improve this answer
    
Do I put that code in the crontab file? How do I check the file is executable as the user I am running the cronjob as? –  user826855 Aug 7 '11 at 16:16
1  
@user826855: If you have to ask something as basic as that then you shouldn't be doing any of this. –  Iain Aug 7 '11 at 16:20
    
edited code to show it as an example cron line based on your info provided, but plus 1 on Iain, be very careful if you dont know what your doing –  anthonysomerset Aug 7 '11 at 16:21
    
@Iain Everybody has to start somewhere, plus I'm on a testing server, so it mistakes don't really matter. –  user826855 Aug 7 '11 at 20:22
    
@user826855: faq –  Iain Aug 7 '11 at 20:37
add comment

I don't think you can change the location of a users crontab file. They are usually located /var/spool/cron/crontabs/<username> Why do you want to place a crontab in /var/www/cron ?

Does email.php contain a shebang line at the top #!/usr/bin/php (or similar) if is doesn't then you should add one.

If email.php does have a shebang ensure that it is executable by the user who is running it.

Is cron running ?

ps -ef | grep cron | grep -v grep
root      4148     1  0 Aug04 ?        00:00:00 crond

if not start it.

share|improve this answer
    
I don't want to place a crontab in "/var/www" I just want to execute some files as a cron that are located in "/var/www". What does "#!/usr/bin/php" do? –  user826855 Aug 7 '11 at 16:36
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.