Tips & Tricks, Tutorials, Hacking, Troubleshooting,

We have previously written about using crontab in Linux to automate tasks (see our post, Automating Tasks in Linux Using Crontab). You don’t have to memorize the commands listed in that post, even though they are not complicated. You may not set up crontab entries often enough to remember the syntax. There is a helpful website, called Corntab, which is a visual crontab utility. It allows you to easily create a crontab entry that you can copy and paste or email to yourself.

To start creating your crontab entry, visit the Corntab website:

http://www.corntab.com/

On the main Corntab page, click the create your crontab now link.

Clicking create your crontab now link

The page for creating your crontab entry visually displays.

Create page on Corntab

For this example, we are going to set up a crontab to run a backup script at midnight every night, putting the results into a log file.

The Minute section automatically displays. To set the minutes for 0 minutes after midnight, click the each selected minute tab under the Minute heading and click 00.

Selecting the 00 minute

To specify midnight, click the Hour heading and click the each selected hour tab. Click 00.

NOTE: The times in crontab are set based on a 24-hour clock. For example, 5:00 pm is 1700 on a 24-hour clock and midnight is 0000. The 24-hour clock is also referred to as military time or astronomical time.

Selecting midnight (00) for hour

To enter the command for running the backup script, click the Command heading. An edit box displays. Enter the following line in the edit box.

/home/lori/user_guide_backup.sh 2>&1 > /var/log/backup_results.log

This command runs a backup script called user_guide_backup.sh and writes the results to a file called backup_results.log. See our post, Back Up a Directory in Linux using a Shell Script, for more information about this backup script. We are specifying a different time in the crontab for this post, but you can get the commands for the backup script from the post listed.

Entering the command to run

Now, we will open a Terminal window to access the crontab editor. DO NOT close the Corntab web page where you set up the crontab entry. We will get back to that web page to copy the entry.

To open a Terminal window, select Accessories | Terminal from the Applications menu.

Opening a Terminal window

Generally, vi is the default editor for editing the crontab entries. However, we find it easier to use a graphical text editor, like gedit, to edit the crontab entries. To use gedit to edit the crontab, enter the following line at the command prompt and press Enter.

env EDITOR=gedit crontab -e

This sets the EDITOR environment variable to gedit, changing the default text editor to gedit only for the current Terminal window session.

Opening the crontab editor

Now, go back to the Corntab web page in your browser and highlight the crontab entry that was generated in the yellow edit box towards the top of the page. Press Ctrl + C to copy the text.

NOTE: Do not close the Corntab web page yet. We have one more feature of Corntab to show you later in this post.

Copying the crontab entry from Corntab

Activate the gedit window that opened with the crontab file. Go to the bottom of the crontab file, and paste the copied crontab entry after the last line in the file.

NOTE: There may be other crontab entries in the file. The order of the entries in the file does not matter.

Click Save.

Pasting the crontab entry into the crontab file

Close gedit by selecting Quit from the File menu.

Closing gedit

Because we did not have any crontab entries in our crontab file, a new, empty crontab was used. When we finished editing the crontab, a message displayed, telling us that a new crontab was installed.

To close the Terminal window, type “exit” (without the quotes) at the command prompt and press Enter.

Installing new crontab

You can also email yourself the crontab entry you created on the Corntab web page. To do this, click the email crontab button below the yellow edit box containing your crontab entry.

Clicking email crontab

The Send crontab to your email address popup box displays. Enter your email in the Your email address edit box. The Your crontab edit box is automatically filled with the crontab entry you created. Click Send email.

Sending email

The email comes from hello@corntab.com and looks similar to the following message:

As you requested, here is the crontab entry you created on Corntab.com
Copy and paste this into your Linux servers crontab by running crontab -e
0 0 * * * /home/lori/user_guide_backup.sh 2>&1 > /var/log/backup_results.log
http://www.corntab.com

If you have an iPhone or an iPod Touch, you can also install the free Corntab app from the App Store. It operates in a similar way to the web site. Simply, select each part of the crontab entry from the bar at the top of the app and select the desired value.

14_corntab_app_on_iphone_orig

You can type the created entry directly into crontab. You can also email it to yourself using the send button in the lower, right corner of the app, just like you can from the Corntab web site. Then, you can copy and paste the entry into crontab from the email.

No comments:

Post a Comment