0

How to schedule a task to linux server system using php script? For example, I need php script to schdule a task for system to run bash script which will backup my files to zip archive? Is there a way to do it?

J.Olufsen
  • 12,049
  • 39
  • 108
  • 171
  • 2
    http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/ this is an article on creating cron jobs, should get you on your way. – CBusBus Jan 16 '12 at 21:42
  • what about php which will pass a bash file to cron to execute it? – J.Olufsen Jan 16 '12 at 21:44
  • looks like a dupe of http://stackoverflow.com/questions/4421020/use-php-to-create-edit-and-delete-crontab-jobs – ben Jan 16 '12 at 21:47
  • Why don't you just schedule your bash script to run with cron? Any particular reason to have a PHP script excecute your bash script? – Michael Mior Jan 16 '12 at 21:55

2 Answers2

2

Most comments are in reference to cron jobs but I wonder if you might be able to simply use the at command.

`at 12:30 dosomething.sh`

If you want a recuring type scheduling solution then cron is the correct path and you should look at this question.

Community
  • 1
  • 1
Andrew White
  • 50,300
  • 17
  • 108
  • 132
2

If you have access to ssh on that machine you can simply schedule your task using linux's crontab. While logged in, type crontab -e which will bring up an editor with the current cron jobs for that user. The syntax is simple, it is composed from 6 parameters, an example line would be :

* * * * * /usr/bin/php -f /path/to/your/php/file

the parameters stand for :

minute hour day_of_month month day_of_week command_to_run

and the command above will run at_every_minute of_every_hour any_day_of_the_month of_every_month any_day_of_the_week

If you would like to schedule a task to run at 5:05 am on all mondays of every month it will be something like :

5 5 * * 1 /usr/bin/php -f /path/to/your/php/file

A really nice tool is http://corntab.com which will help you schedule your command.

capi
  • 1,443
  • 12
  • 10