# Crontab例行性工作排程 Linux中要使系統在特定時間進行指定動作時,可使用crontab ## 查詢排程 ``` $ crontab -u <使用者> -l #查看使用者的工作排程 ``` ## 編輯 ``` $ vi /etc/crontab #crontab設定檔 ``` 或 ``` $ crontab -e #非管理員的使用者編輯 $ systemctl restart crond #重啟cron服務 ```` :::info :information_source: 格式 ``` # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed ``` * [\*]:代表任何時刻 * [,]:代表分隔時段 `例: 0 1,2 * * * command #表示每天早上1點0分和2點0分會執行command` * [~]:代表一段時間 `例: 0 1~15 * * * command #表示每天早上1點到下午3點之間每次整點會執行command` * [/n]:代表每隔n時間執行一次 `例: */5 * * * * command #表示每隔5分鐘執行一次command ` ::: ## 查看log ``` $ sudo less /var/log/cron #查看crontab執行紀錄 ``` ## 刪除排程 ``` $ crontab -r #刪除所有排程 ``` --- #### 參考連結 [Linux 排程設定](https://blog.gtwang.org/linux/linux-crontab-cron-job-tutorial-and-examples/) [Ubuntu 排程設定](https://jqnets.com/blog/ubuntu-%E6%8E%92%E7%A8%8B%E8%A8%AD%E5%AE%9A-%EF%BC%9Acrontab-%E6%8E%92%E7%A8%8B%E4%BD%BF%E7%94%A8%E6%95%99%E5%AD%B8/) ###### tags `RHCSA`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up