Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add cron tasks in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to add cron tasks to Linux. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Cron is one of the most useful utilities you can find in any Unix-like operating system. It is used to schedule commands to be executed at specific times. These predetermined commands or tasks are called "Cron tasks." Cron is commonly used to run scheduled backups, monitor disk space, periodically delete files that are no longer needed (such as log files), run system maintenance tasks, and so on.

Add cron tasks from the command line

To add cron tasks, you can use a command-line tool called crontab.

Entering the following command creates a new cron task that runs as the current user.

1.$ crontab -e

If you want to run cron tasks as other users, enter the following command.

1.$ sudo crontab -u -e

You will see a text editing window where you can add or edit cron tasks. Use the nono editor by default.

How to add cron tasks to Linux How to add cron tasks to Linux

Each cron task has the following format.

1.

The first five elements define the plan for the task, and the last element is the complete path to the command or script.

Here are some cron task examples.·* * * * /home/dan/bin/script.sh: runs every minute. 0 * * * /home/dan/bin/script.sh: runs hourly.·0 0 ** /home/dan/bin/script.sh: runs at midnight every day.·0 9,18 * * /home/dan/bin/script.sh: runs daily at 9AM and 6PM.·0 9-18 * * * /home/dan/bin/script.sh: runs every hour from 9AM to 6PM.·0 9-18 * * 1-5 /home/dan/bin/script.sh: runs hourly from 9AM to 6PM Monday through Friday.·*/10 * * * /home/dan/bin/script.sh: runs every 10 minutes.

Once you have completed the setup steps above, press Ctrl+X to save and exit the editor. At this point, the new planned task should have been activated.

To view existing scheduled tasks, use the following command:

1.$ crontab -l Add scheduled tasks from GUI

If you're in a Linux desktop environment, you can use crontab's more user-friendly GUI front end to add or add a cron task.

On the Gnome desktop, there is a Gnome Schedule (gnome-schedule package).

In the KDE desktop, there is a Task Scheduler (kcron package).

Thank you for reading! About "how to join cron tasks in Linux" this article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report