Editing the Crontab

You may already be familiar with setting up Crons in cPanel ( a guide for this can be found here) but you may be looking to have more direct control over all the crons via SSH on your server.

You can access your server’s Crontab using the following command:

# crontab -e

By default, you will likely have several cPanel crons in here, such as backups that will be in this format:

30 23 * * * /usr/local/cpanel/scripts/upcp –cron

Cron Format

Crons all have the following format:

[minute] [hour] [day-of-month] [month] [day-of-week] [path-to-script]

  • Minute can range from 0-59
  • Hour can range from 0-23
  • Day-of-month can range from 0-31
  • Month can range from 1-12 (Where 1 = January and 12 = December)
  • Day-of-week can range from 0-7 (Sunday can be either 0 or 7

Examples

Looking back at our cPanel backup example: 30 23 * * * /usr/local/cpanel/scripts/upcp –cron

This means that cpanel backups run at the 30th minute of the 23rd hour every-day, or 11:30 PM.

If you wanted backups to run at midnight, you would simply need to edit the Cron to the following:
0 0 * * * /usr/local/cpanel/scripts/upcp –cron

Now, if you say you have your own script that you would only like to run on weekdays at a certain time, you can do the following:

30 0 * * 1,2,3,4,5 /path/script/script.sh OR 30 0 * * 1-5 /path/script/script.sh

This will run ‘script.sh’  Monday-Friday at 12:30 AM

You can also have scripts run every X for a variable so, for example, if you wanted your script to run every 5 minutes you can do the following:

5 * * * 1,2,3,4,5 /path/script/script.sh OR 30 0 * * 1-5 /path/script/script.sh

 

Other Options for the Crontab Command

  • crontab -l     : Display the Crontab
  • crontab -r   : Remove the Crontab
  • crontab -u USER -e    : Edit the crontab for a specific user

 

Hopefully you are now more familiar with editing the Crontab on your server. If you have any questions or concerns feel free to submit a ticket or contact us via our live support system.

  • 0 Kunder som kunne bruge dette svar
Hjalp dette svar dig?

Relaterede artikler

Connect using Putty to a Linux Server

This article covers how to connect using Putty to a Linux Server. 1. If you haven't already,...

How to Create a Full cPanel Backup through SSH

This article will guide you on how to create a full cPanel backup through SSH. Note: The syntax...

Useful cPanel Scripts

This article covers some useful scripts built into cPanel! cPanel Update /scripts/upcp  This...

How to Set up Auto Login to PHPMyAdmin

How to Set up Auto Login to PHPMyAdmin    This article covers how to setup Auto Login to...

Fix Webalizer not Updating Problem in cPanel

Fix the Webalizer not Updating Problem in WHM/cPanel The Webalizer is a fast, free web...