Linux crontab 指令用法與範例

本篇介紹 Linux crontab 指令用法與範例,想要在 Linux 電腦中排程工作就可以使用 crontab,讓 Linux 系統定時地自動去執行指定的腳本或程式,詳細內容與範例如下,以下指令適用在 Ubuntu 或其它 Linux,

列出目前自己的 crontab 設定內容,

1
crontab -l

編輯 crontab 內容,

1
crontab -e

以下是 Ubuntu 下 crontab 的範例,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
~/bin $ crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/5 * * * * /home/user/bin/xxx # 每隔 5 分鐘執行一次
59 23 * * * DISPLAY=:0 ~/crontab_script/xxx.sh # 23:59 時執行

其他參考
Linux 設定 crontab 例行性工作排程教學與範例
https://blog.gtwang.org/linux/linux-crontab-cron-job-tutorial-and-examples/

以上就是 Linux crontab 指令用法與範例介紹,
如果你覺得我的文章寫得不錯、對你有幫助的話記得 Facebook 按讚支持一下!

其它相關文章推薦
Linux 常用指令教學懶人包