幫助中心
這里有最新的使用文檔和教程
Linux系統(tǒng)有系統(tǒng)時間和硬件時間之分:
系統(tǒng)時間: 一般說來就是我們執(zhí)行 date命令看到的時間,linux系統(tǒng)下所有的時間調(diào)用(除了直接訪問硬件時間的命令)都是使用的這個時間。
硬件時間:主板上BIOS中的時間,由主板電池供電來維持運行,系統(tǒng)開機時要讀取這個時間,并根據(jù)它來設(shè)定系統(tǒng)時間(注意:系統(tǒng)啟動時根據(jù)硬件時間設(shè)定系統(tǒng)時間的過程可能存在時區(qū)換算,這要視具體的系統(tǒng)及相關(guān)設(shè)置而定)。
1、查看當前系統(tǒng)時間date:
[root@surfer ~]#date
2018年06月 26日星期二 10:09:21 CST
2、設(shè)置系統(tǒng)時間date -s +時間
[root@surfer ~]#date -s 10:10:10
2018年06月 26日星期二 10:10:10 CST
3、設(shè)置系統(tǒng)時間時,如果還需要設(shè)置日期,則要將日期與時間值用雙引號包裹起來
[root@surfer ~]#date -s "2018/8/8 10:00:00"
2018年08月 08日星期三 10:00:00 CST
4、查看硬件時間用hwclock或者clock命令:
[root@surfer ~]#hwclock
2018年06月26日 星期二 10時13分02秒 -0.805503 秒
[root@surfer ~]#clock
2018年06月26日 星期二 10時13分07秒 -0.507462 秒
5、將硬件時間寫入到系統(tǒng)時間:
[root@surfer ~]#hwclock -s
6、將系統(tǒng)時間寫入到硬件時間
[root@surfer ~]#hwclock -w
7、時間同步,Linux系統(tǒng)需安裝ntpdate
檢查是否安裝了ntpdate : rpm -qa | grep ntpdate
如果沒有安裝則運行如下命令:yum install ntpdate
時間同步命令:ntpdate ? ?www.pool.net.org?? ,其中 ? ?www.pool.net.org?? 是互聯(lián)網(wǎng)中標準時間服務(wù)器
8、contab命令
通過vi /etc/crontab命令可以看到定時任務(wù)的書寫格式
[root@surfer ~]# vi/etc/crontab
SHELL=/bin/bash #SHELL變量指定了系統(tǒng)要使用哪個shell
PATH=/sbin:/bin:/usr/sbin:/usr/bin #PATH變量指定了系統(tǒng)執(zhí)行命令的路徑
MAILTO=root #MAILTO變量指定了crond的任務(wù)執(zhí)行信息將通過電子郵件發(fā)送給root用戶,如果MAILTO變 量的值為空,則表示不發(fā)送任務(wù)執(zhí)行信息給用戶
For details seeman 4 crontabs
Example of jobdefinition:
.---------------- 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
在以上各個字段中,還可以使用以下特殊字符:
星號(*):代表所有可能的值,例如month字段如果是星號,則表示在滿足其它字段的制約條件后每月都執(zhí)行該命令操作。
逗號(,):可以用逗號隔開的值指定一個列表范圍,例如,“1,2,5,7,8,9”
橫杠(-):可以用整數(shù)之間的橫杠表示一個整數(shù)范圍,例如“2-6”表示“2,3,4,5,6”
斜線(/):可以用斜線指定時間的間隔頻率,例如“0-23/2”表示每兩小時執(zhí)行一次。同時斜線可以和星號一起使用,例如*/10,如果用在minute字段,表示每十分鐘執(zhí)行一次。
crontab -l :列出當前用戶的crontab文件內(nèi)容
*/usr/local/gse/agent/bin/gsectl watch
crontab -e :編輯當前用戶的crontab文件內(nèi)容
[root@surfer data]#crontab -e
*/1 * * * * echo"hello world">>/data/code.txt
~
在這里我添加了一個定時任務(wù)*/1 * * * * echo"hello world">>/data/code.txt :意思是每一分鐘打印一次hello world,并且重定向到了/data/code.txt文件里面,幾分鐘過后查看code.txt,出現(xiàn)了如下內(nèi)容,說明這個定時任務(wù)已經(jīng)開始執(zhí)行
[root@surfer data]# cat code.txt hello world hello world hello world hello world hello world hello world hello world hello world hello world