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 want to perform a job every day on the server side, for example at 01:00 AM, and I was told that I can use a cron job.

If I execute crontab cron.txt for a specific time, let's say 02:00 every day, and then I amend the date in cron.txt (to 06:00 for example), do I have to re-execute the cron.txt file again?

share|improve this question

migrated from stackoverflow.com Oct 31 '11 at 0:15

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

closed as off topic by Ward, Shane Madden, Iain, mailq, voretaq7 Nov 21 '11 at 14:46

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
    
Don't understand the question... –  Nico Oct 30 '11 at 23:57
    
cron will run the statement and end as the process ends. If you want/need to rerun on a schedule, you need to setup cron to do that, or (not recommended) find a way to keep the process alive and monitoring the current (to the process) time. –  Jared Farrish Oct 30 '11 at 23:58
    
maybe this would be better here: unix.stackexchange.com –  javamonkey79 Oct 31 '11 at 0:10

2 Answers 2

Yes, because the list of cron jobs is saved in the crontab file.

crontab cron.txt replaces the current crontab with the contents of your file. (It doesn't link it, for instance).

Note that you will erase all other jobs in the file with this command.

You can see the current contents of your crontab with crontab -l.

share|improve this answer

Be sure to make your script executable.

$ chmod +x script.php

Then move it to /etc/cron.daily/.

# mv script.php /etc/cron.daily/

Also, be sure to add #!/usr/bin/php to the script!
The script should now execute once every day, assuming you're on a Linux based operating system.

share|improve this answer
    
Which will only work if you have root access. –  Leonid Shevtsov Oct 31 '11 at 0:06
    
@LeonidShevtsov Yes, the OP didn't specify whether he had root access or not though. –  Griffin Oct 31 '11 at 0:08
    
@LeonidShevtsov This is a site for systems admins. We assume everyone has administrative access to their machines unless they state otherwise. –  MDMarra Oct 31 '11 at 0:19
    
@MarkM, question migrated from StackOverflow –  Leonid Shevtsov Oct 31 '11 at 0:24
    
@LeonidShevtsov My mistake, I misread the migration timestamp. Apologies. –  MDMarra Oct 31 '11 at 0:30