Knowledgebase: PHP
Running Shell Scripts With Crontab
Posted by Barry Tarbet on 24 March 2008 07:06 PM

Running Shell Scripts With Crontab *

Crontab allows you to clock and run your own Unix shell scripts automatically. It is available only in Unix-based plans and requires the knowledge of Unix shell commands.

To enable crontab jobs, do the following:

  1. Login to your H-Sphere control panel
  2. Select FTP/User Account
  3. Select FTP Manager
  4. Enable Crontab if disabled
  5. Agree with charges, if any.
  6. Click the Edit icon for Crontab.
  7. On the page that appears, add the crontab job:

    Commands are executed by cron when the minute, hour, day and month fields match the current time, and when at least one of the two day fields (day of month, or day of week) match the current time. If you want to set any minute, hour, day, enter * symbol.

    In the Command box write a command to be executed by cron, i.e. path relative to your root home directory.

    The Mail-To address is where the system will direct reports if errors occur.

To delete a job, check the box in the Delete section and click Submit Query.

 

to Run PHP you need to include the path of php in your command line - example

/hsphere/shared/php5/bin/php-cgi /hsphere/local/home/yourAccount/yourDomain.com/cronjob.php

depending on the PHP version you require
replace  PHP5 with the correct version 

example - if your using php55:

/hsphere/shared/php55/bin/php-cgi /hsphere/local/home/yourAccount/yourDomain.com/cronjob.php

 

 

If you do not wish emails with the output of the script make sure the script outputs to the bin:

/your-script.php > /dev/null

if you also want the errors supressed:
/your-script.php > /dev/null 2>&1

Normally cron will email you the output. If the output is send to the bin, there will be no email as cron has nothing to report!

See also:
http://serverfault.com/questions/175324/dev-null-and-dev-null-21

For setting up timing, see:
http://www.thesitewizard.com/general/set-cron-job.shtml

 

 

* Unix only

If you have any further questions, please submit a support ticket - at www.OccSupport.com

(162 vote(s))
Helpful
Not helpful