Simplehost Web Hosting

Setup a crontab entry

Sometimes you need to run a script to update your website in some way, and a crontab is often a great solution.

First off, if you haven't logged into your account using SSH you may need to send a request to get it enabled.

I'm connected how do I edit?

Once logged in via SSH you can edit your crontab file.  An easy to use file editor called nano is a good choice - so we set that as an editor and then start editting.

Enter the below without comments (# symbols in front)

# export EDITOR=nano

# crontab -e

Now we're editting, what do I enter?

If you need any help or advice adding a crontab entry don't hesitate to let us know.

Check out below for some crontab examples.

When working in nano you can use the arrow keys to move to the line below the first line.  An example of a crontab file is shown below.  Here a single entry is running a script daily

# m h  dom mon dow   command

45 18 * * * /home/username/website.co.nz/scripts/update_stock.sh #Runs at 6:45 pm every day

 

Save your entry by using the key sequence Ctrl + X.

This will exit nano, when prompted enter Y (Yes) to save the updates.

Well done! check you're crontab runs as expected, you may receive email to your simplehost contact email address if there is output from your script.

 

Crontab Kung Fu

A crontab entry has six fields to specify the run time.  These are (in order).. minute, hour, day of the month, month and day of the week.

*     *     *     *     *  command to be executed

-     -     -     -     -

|     |     |     |     |

|     |     |     |     +----- day of week (0 - 6) (Sunday=0)

|     |     |     +------- month (1 - 12)

|     |     +--------- day of month (1 - 31)

|     +----------- hour (0 - 23)

+------------- min (0 - 59)

Here is a few examples..

30 * * * * <command> #Runs at 30 minutes past the hour

45 6 * * * <command> #Runs at 6:45 am every day

45 18 * * * <command> #Runs at 6:45 pm every day

00 1 * * 0 <command> #Runs at 1:00 am every Sunday

00 1 * * 7 <command> #Runs at 1:00 am every Sunday

00 1 * * Sun <command> #Runs at 1:00 am every Sunday

30 8 1 * * <command> #Runs at 8:30 am on the first day of every month

00 0-23/2 02 07 * <command> #Runs every other hour on the 2nd of July

When you receive output (in email) from your script and wish to silence it you can redirect the output to accomplish this.  Here's an example..

30 * * * * /home/user/website.co.nz/scripts/run_update.sh >/dev/null 2>&1
Recent News
Feb 13, 2016

We have deployed PHP 7.0 to selected servers which has up to 4x performance gain on previous versions as well as the most comprehensive language API available. Read More


Feb 08, 2015

Bitcoin payments are now accepted for all hosting products. Bitcoin payments are simple, fast and simple to do on a mobile device. Get your digital wallet today and pay with Bitcoin. Read More