DreamHost Crontab

If you have a website then you might have heard the name cronjob. You may not have the idea why cronjob is used that is why you started searching on it. Cronjob is a special feature offered in Unix based system. Cronjob is used to automate certain task on the server. These tasks are performed using commands. So say, if you want to run some command at a specific time on regular interval then you can automate it using cronjob. Crontab is the command used to setup cronjob.

Since DreamHost servers run on Ubuntu, a variation of Linux system, you will get the crontab command on all of there systems. You can use crontab directly on the SSH terminal. If you are not a technical person then you can use DreamHost panel to setup cronjob. Even if you are a technical person then also you can use DreamHost panel. That is the easy way of setting cronjob.

Cron Job Video

If you like to learn how to use cronjob by watching the video then watch the following video.

Set Up Cron Job Using DreamHost Control Panel

If you want to setup Cronjob using Dreamhost panel then you need to follow these steps.

1) Login to DreamHost panel using webID and password.

2) In the leftside navigation panel, click on Goodies section.

3) You will see more options. Click on Cron Jobs link.

4) Click on Add New Cron Job button. You will have to give the cron job details.

DreamHost CronJob

5) Select the user under which you want to run the cronjob. Please make sure that you have SSH enabled for atleast one user. If you haven’t enable SSH for a single user then you won’t get any username option there.

6) Enter the title. Title is just for your reference.

7) Enter email address on which you want to get the output of the running command.

8) Enter the command to run. Please use absolute paths for every file and programs while specifying the command.

9) Select the time period. You can select from hourly, daily, weekly, monthly or set a custom time.

10) Finally, click on Add button.

That’s it. You have now added the cronjob to your account.

Set Up Cron Job Using SSH

DreamHost panel offers easiest way to setup cron job. You don’t have to do it your way using SSH command but still if you want to do it your own using SSH command there here is how you can do it.

First login to your server using SSH. We will use crontab command to setup cronjob. Crontab command has three parameters.

“crontab -e” – Used to edit crontab file.

“crontab -l” – Used to list all set cronjobs.

“crontab -r” – Used to remove all cronjobs.

We will use crontab -e for setting cronjob. This command opens crontab configuration file in default editor.

Crontab File Format

You need to setup single cron job in single line. Here is the format for setting cronjob.

* * * * * command

The first * is for minutes of an hour. You can set values from 00 to 59 for first field.

The second * is for hour of the day. You can set values from 00 to 23.

The third * represents the day of the month. You can set values from 01 to 31.

The forth * is for month of the year. You can use the values from 01 to 12 for this field.

The last * represents day of the week. You can enter anything from 0 to 7. 0 and 7 both represent Sunday where 1 to 6 represent Monady to Saturday respectively.

Here are some of the examples of cronjobs.

00 00 * * *      touch /home/user/file.html

This cronjob runs on mid night every day which execute touch command.

01  00 * * 0     touch /home/user/file.html

This cron runs on every Sunday at 00:01 which runs the command touch.

When the cronjob entries are added, you will have to save the file. Now your cronjobs are set.

Run PHP Using DreamHost Cron Jobs

If you want to execute any PHP file at a regular time interval then you will have to just use php command for running php file.

Let’s take a example. Suppose you want to execute /home/user/scripts/file.php every day. Here is a cronjob for that.

00 00 * * * /usr/local/bin/php      /home/user/scripts/file.php

Whether you run the above command or run the file in browser, you will have same output.

Now you have a full understanding of setting cronjob.