DreamHost Crontab

Crontab is used to perform scheduled tasks in UNIX system. There are some tasks that you want to perform at scheduled time. If you want to automate those tasks then you need to use crontab service. I use cron tab to create xml site map of this web site every day.

Since DreamHost offers web hosting service using debian(Linux) system, you can set cronjob in your DreamHost account. If you are technical person and aware with the crontab syntax, you can enable SSH in DreamHost and directly set cron job using ‘crontab -e’ command.

What if you are a non technical person and want to set up cron job in DreamHost? Well, as always DreamHost has made it simple using panel.

Set Up Cron Job Using DreamHost Panel

To set a cron job using panel, log in to your DreamHost panel account.  Now click on ‘Cron Jobs’ option under the ‘Goodies’ section.

Here you can add/edit your cron jobs. Click on ‘Add New Cron Job’ button and you will be asked the details for your new cron job.

DreamHost Cron Job

Select the user under which you want to perform the cron job. Only shell users can perform cron jobs. So if you haven’t enable shell access for any of the user then you can’t set up cron job. Enable shell access for the user under which you want to perform cron job.

Give the title name. This is just for your reference. You can give title any you want. Give your email address. You will get an output of your task on this email. If any error happens while running your command then also you will get notification. You can leave it blank if you don’t want the output of your tasks but I highly recommend that you put your email address there.

Now you need to give the command which you want to run at scheduled time. While giving command, make sure that you enter absolute paths for every file & every program.  

You can leave the ‘Use locking’ option checked. Finally enter the scheduled time and click on ‘Add’ button.

Your cron job is set up now.

Set Up Cron Job Using SSH

Since DreamHost provides a really simple way to set up cron job, you don’t need to do it by hand. But if you want to do it by hand, here is what you need to do.

Log in to your SSH account. Now you need to use ‘crontab’ to set up cron job.

crontab -e’ - Opens your default editor to edit the crontab file.

crontab -l’- Lists your currently set up cron jobs.

crontab -r’ - Delete your cron jobs.

To set up a new cron job, use ‘crontab -e’ command. You will be shown crontab file in your default editor. You just need to add cron job in the file and save it.

Crontab File Format

You need to enter each cron job in one line. Each cron job entry looks like the following.

* * * * * command

The first * represent minute of an hour. It can be anything from 00 to 59.

The second * represent hour of a day. It can be anything from 00 to 23.

The third * represent day of the month. It can be anything from 01 to 31.

The forth * represent month of a year. It can be anything from 01 to 12.

The fifth * represent day of a week. It can be anything from 0 to 7 where 0 and 7 both represent Sunday and 1 to 6 represent Monday to Saturday respectively.

Here are few examples of cron job entries.

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

This cron job will run on every night at 00:00 which execute the command ‘touch /home/user/file.html’

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

This cron job will run on every Sunday at 00:00 which execute the command ‘/home/user/file.html’.

After entering cron job entries, just save the crontab file and your cron jobs are set at scheduled time.

If you have already setup cron jobs by hand and want to use DreamHost panel to setup new cron jobs, you can do it. DreamHost panel doesn’t overwrite your crontab file. It just append the new cron job entries to the file. So your hand set up cron jobs are safe.

Run PHP Using DreamHost Cron Jobs

If you want to run some PHP files at scheduled time, you can do that also using DreamHost cron job. You just need to use php command.

This is how it works. Just create a new cron job and in the command line use following syntax.

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

Of course, you need to change the file path in the above syntax. The above command run the php file /home/user/scripts/file.php. This is same as accessing the /home/user/scripts/file.php file in browser.

I hope you like the article on DreamHost cron job.

Go To DreamHost How To

Go To Home