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'm trying to run a scheduled task on my shared Linux server using the crontab via Terminal on my Mac.

I can login to my ssh OK, and can view directories etc with ease.

I try and create/edit my crontab by using...

crontab -e

But i get the response

no crontab for [username] - using an empty one

So trying to then add my line to set my schedule up, and Terminal just doesn't seem to respond.

10 * * * * /home/username/www/myphpfile.php

Any clues what on earth I'm doing wrong? Or a link to a clear step-by-step tutorial?

I have checked with the webhost that this is supported, it's just undocumented!

All I want to do is run a php script every so often through the day (to check for updates to an XML file).

share|improve this question

migrated from stackoverflow.com Feb 15 '10 at 22:52

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

4  
What do you mean, "Terminal just doesn't seem to respond"? Are you not presented with a text editor in which to specify your cron jobs? –  FRKT Feb 15 '10 at 22:37
add comment

4 Answers

I'm betting the $EDITOR variable is set to vi(m).

If you press i to go to interactive mode are you then able to enter your crontab?

If so after you are done entering your cron entry, press escape then type :wq<enter> to save your changes.

Also, learning vi(m) is a good thing check out: http://acs.ucsd.edu/info/vi_tutorial.shtml for a beginner's tutorial.

share|improve this answer
    
great, i'll give this a try. it's not something i ever thought i'd use, so it's completely alien to me. I'll let you know how I get on –  user34990 Feb 16 '10 at 9:13
add comment

try to set EDITOR environment variable, for example doing:

EDITOR=nano
export EDITOR
share|improve this answer
    
While Zepher's correct that it's the default vi editor Shuvalov is spot on about changing the default editor. Try his suggestion in one line: export EDITOR=nano –  Patrick R Feb 16 '10 at 1:04
add comment

Your mistake is that you don't call the PHP interpreter at all. Use this instead:

// Assuming your PHP executable resides under /usr/local/php5/bin
10 * * * * /usr/local/php5/bin/php /home/username/www/myphpfile.php

Good luck.

share|improve this answer
1  
Your mistake is that you forget about the #! line. Use it and chmod +x instead. –  grawity Feb 16 '10 at 9:29
add comment

Looks like one of two possibilities.
1. There is a problem with cron
2. There is a problem with php from the command line

  1. Try a simpler command like touch or copy to make sure the cron is working.

  2. Is the php command line interface installed on your hosting service? If so, then maybe you need to review your code to use the CLI effectively

Hope this helps

share|improve this answer
add comment

Your Answer

 
discard

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