Setting up Cron Job Using crontab

Source: Internet
Author: User

Setting up Cron Job Using crontab:
Step 1:open a Terminal windows (Command line) in Linux.

Step 2:the Following is a list of cron directories:/etc/cron.hourly

/etc/cron.daily
/etc/cron.weekly/etc/cron.monthly

Copy your shell script ' script.sh ' or ' script ' into one of the directories above. If you are need to run the script hourly, place your script file in the "cron.hourly" folder. For daily, where it inside the "cron.daily" and so forth.

Step 3:give The shell script the correct permission. For example, if the script is called "script.sh", set permission as follows:

Cd/etc/cron.daily/chmod 755 script.sh

Step 4:add The new cron job to crontab:
Crontab–e
This is opens VI editor for you. Create the cron command using the following syntax:

1.2.3.4.5.6.

More

The number of minutes after the hour (0 to 59)
The hour in military time (hour) format (0 to) the "Day of" month (1 to 31)
The month (1 to 12)
The day of the week (0 or 7 are Sun, or use name) the command to run

Graphically they would look like this:

* * * * * Command to be executed-----| | | |

| |

| |

| |

|    +-----------Hour (0-23)
+-------------Min (0-59)
|     |     +-----Day of Week (0-7)
|     +-------Month (1-12)
+---------Day of Month (1-31)

An example command would is "0 0 * * */etc/cron.daily/script.sh". Thiswould mean that shell script would exactly execute at midnight Everynight.

To save the changes to the crontab so you just made, hit ESC key, Andthen type:w and followed to exit.

To list existing cron jobs:

Crontab–l

To remove an existing cron job:

Enter:crontab–e

Delete the line that contains your cron job hitesc>:w>:q

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.