DreamHost Crontab

Cronjob is feature in Unix based system. Cronjob is used to perform scheduled tasks. There are certain tasks in your hosting management which you need to perform at specific time. You can automat these types of tasks using cronjob.  Crontab is a linux command which you can use to set cronjob. I use crontab to create an xml sitemap for this website.

All DreamHost servers run on Ubuntu(Linux) system. That’s why you can use crontab in your DreamHost account. If you are a technical person and want to set cronjob then you can enable SSH in DreamHost and set cronjob using ‘crontab -e’ command.

If you are not a technical person and want to set cronjob in your DreamHost account then also you can easily do so. DreamHost has made it simple using panel.

Cron Job Video

In the following video, I have shown how to setup a cron job using DreamHost panel. Watch the video to learn it.

Set Up Cron Job Using DreamHost Panel

If you want to setup cronjob using DreamHost panel then first login to panel using your email id and password. Click on “Cron Jobs” link under the Goodies section.

From this page, you can add or edit cron jobs. Click on “Add New Cron Job” button and you will be asked for the cronjob details.

DreamHost Crontab

You need to select the user under which you want to run the cronjob. Cronjobs are run under shell users. So if you haven’t enable shell access for any user then you need to enable it. Then only you can select the user for which you want run cronjob.

Then you need to give the tile for your cron job. This is for your reference. You can give anything you like. Enter the email address. On this email, you will get the output of cronjob. If any error happens then you can find it from the output. If you don’t want to get the email then leave it blank. I would suggest that you put your email address there.

Finally, you need to enter the command which you want to run at scheduled time. Make sure that you have entered the absolute paths for every file and programs otherwise command may not work as expected.

Leave the User Locking option checked. Select the time when you want to run the command. You have whole variety of options for selecting time. Click on “Add” button and your cronjob is added now.

Set Up Cron Job Using SSH

DreamHost offers an easy way to set cronjob. So you don’t need to do it your own but if you still want to set cronjob your own way then here is how you can do so.

First make sure that you have shell account enabled. Login to SSH account. You need to use “crontab” command to set cronjob.

“crontab -e” – This command opens default editor to edit crontab file.

“crontab -l” – This command lists all cron jobs.

“crontab -r” – This command removes the cron jobs.

To set the cron job, use “cronjob –e” command. You will see that cronjob opens configuration file in your default editor. Just add the cronjobs, save the file and done.

Crontab File Format

You need to enter the single cronjob in single line. Use the following format to set cronjob.

* * * * * command

Here first * represents minute of an hour. You can enter any value from 00 to 59.

The Second * represents hour of the day. You can enter any value from 00 to 23.

The Third * represents the day of the month. You can enter any value from 01 to 31.

The forth * represents month of the year. You can enter any value from 01 to 12.

The fifth * represents day of the week. You can enter any thing from 0 to 7 where 0 and 7 both represent Sunday and 1 to 6 represent Monday to Saturday respectively.

Let’s look at some examples of cronjobs.

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

The above cronjob runs on every night at 00:00 time which execute the command “touch /home/user/file.html”

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

The above cron will run on every Sunday at 00:01 which runs the command “touch /home/user/file.html”

After entering the cronjob entries in to cronjob file, you need to save the file. Your cronjobs will run at the scheduled time.

If you have manually setup cronjobs and want to use the DreamHost panel to setup new cron jobs then you can do that. DreamHost panel doesn’t overwrite the crontab file. DreamHost cronjob robot will append the new cron job entries in the configuration files.

Run PHP Using DreamHost Cron Jobs

If you want to run PHP file at schedule time then you can set a cron job for it. You just need to use php command to execute the php file.

To set php command, create a new cron job as shown in the following format.

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

You will have to change the file path to run the proper file. The above cronjob is run at 00:00 on every day and execute the file /home/user/scripts/file.php. This is same as running file.ph in the browser.

I hope you now got how to set cronjob in DreamHost.