要使用的主要命令
一 新增或編輯定時任務檔案
[root@instance-nretneiu ~
]# - cp /etc/crontab /home 複製系統定時任務檔案到你的家目錄
[root@instance-nretneiu ~
]# cd /home 進行家目錄
[root@instance-nretneiu home]
# ls -l 檢視目錄下的檔案或資料夾
total 8
-rw-r--r--
1 root root 451 jan 2011:
16 crontab 這個是剛複製的crontab檔案
[root@instance-nretneiu home]
#vim crontab 編輯定時任務檔案
/**下邊是crontab中的檔案內容**/
shell
=/bin/bash
path
=/sbin:
/bin:
/usr/sbin:
/usr/bin
# for details see man 4 crontabs
# example of job definition:
# .---------------- 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
# | | | | |
# 以下的每分鐘往對應的日誌檔案中寫入當前日期,進行測試*/
1***
*echo $(date)
>
>
/home/log.log
二 建立定時任務
[root@instance-nretneiu home]# crontab crontab
[root@instance-nretneiu home]# crontab -l
hell=/bin/bash
path=/sbin:/bin:/usr/sbin:/usr/bin
# for details see man 4 crontabs
# example of job definition:
# .---------------- 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
# | | | | |
*/1 * * * * echo $(date) >> /home/log.log
[root@instance-nretneiu home]#
三 檢視該任務結果
[root@instance-nretneiu home]# cat /home/log.log
mon jan 20 11:55:01 cst 2020
mon jan 20 11:56:01 cst 2020
mon jan 20 11:57:01 cst 2020
mon jan 20 11:58:01 cst 2020
mon jan 20 11:59:01 cst 2020
[root@instance-nretneiu home]#
四 使用crontab -e 編輯定時任務檔案
[
root@instance-nretneiu home]# crontab -e
hell=
/bin/bash
path=
/sbin:
/bin:
/usr/sbin:
/usr/bin
# for details see man 4 crontabs
# example of job definition:
# .--
----
----
----
--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=0or
7) or sun,mon,tue,wed,thu,fri,sat
# | | | | |*/
1***
* echo $(date)
>
>
/home/log.log
五 刪除定時任務
[
root@instance-nretneiu home]# crontab -l 檢視定時任務
hell=
/bin/bash
path=
/sbin:
/bin:
/usr/sbin:
/usr/bin
# for details see man 4 crontabs
# example of job definition:
# .--
----
----
----
--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=0or
7) or sun,mon,tue,wed,thu,fri,sat
# | | | | |*/
1***
* echo $(date)
>
>
/home/log.log
[root@instance-nretneiu home]# crontab -r 刪除定時任務
[root@instance-nretneiu home]# crontab -l 再檢視發現定時任務唄刪除了
no crontab for root
[root@instance-nretneiu home]#
本人也是剛學習中linux菜鳥,以上都是自己親自測試過了的,如果你按照以上的流程出現問題請勿噴,可能是系統差別的問題。 linux 新增定時任務指令碼
主要分2個步驟 第一步 編寫要定時執行的指令碼 touch mytask.sh vi mytask.sh 裡面寫入 bin bash echo date tmp mytask.log 就是將當前時間都追加到mytask.log這個檔案中。儲存後記得要加上執行的許可權 chmod x mytask.s...
MySQL新增定時任務
將定時任務開啟 set global event scheduler 1 設定該事件使用或所屬的資料庫base資料庫 use test 如果原來存在該名字的任務計畫則先刪除 drop event if exists enent create test 設定分隔符為 mysql預設的語句分隔符為 這樣...
Sybase Ase 新增定時任務
準備乙個sh檔案和sql檔案 sh檔案中內容如下 home sybase bash profile logfile home sybase job log.log time date y m d h m echo time job start isql usa p sserver i home sy...