How to Add Cron Job in Hostmonster


Recently I had to create a cron job on a HostMonster server to run a PHP script every X minutes. If you’ve ever searched for a tutorial on how to do this, you’ll know it’s no easy thing to find. After fumbling around and failing for a while, I finally managed to work the kinks out of the job. For those interested, the method I used was:

*/15 * * * * /ramdisk/bin/php5 /home/—hostmonster username here—/public_html/path/to/script.php

The asterisks designate time frequency of the job, in the following order: minute (0-59), hour (0-23), day (1-31), month (1-12 or jan, feb, mar, etc), weekday (0-6 where Sunday is 0 or 7 OR sun, mon, tue, etc). So mine means ‘run once every fifteen minutes’. The ‘*’ means every. If you wanted to run once an hour, it’d be ‘0 * * * *’ meaning ‘run at :00 of each new hour’.

Because I want to run a PHP script, I called PHP through the shell with ‘/ramdisk/bin/php5′. Alternatively, I could’ve used [and have succesfully] ‘php’ and ‘/usr/bin/php’, but HostMonster seems to prefer ‘/ramdisk/bin/php5′.

And finally, the path to the script. Most importantly, don’t forget the leading slash, else the job will return ‘No input file specified’. You can find your home directory on HostMonster by logging into cPanel and looking in the far left column under ’stats’; it’ll display your home directory. Also, don’t forget to input an email address like ‘webmaster@yourdomain.com’ in the cron job setup page on HostMonster so you can verify the job is running properly.

Comments

  1. I have read this article it is really helpful for getting amazing tips on related topic. You have described everything in a professional way.

    marketing companies buffalo ny are available but Crysal Tech Solution provides professional digital marketing service for growing your business.

    ReplyDelete

Post a Comment

Popular posts from this blog

Some mistakes to avoid while looking for a job

How Understanding Cloud Computing Saved a Million Dollars!

How to create test account in moneybookers.com