自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Ubuntu使用crontab定時(shí)任務(wù)

系統(tǒng) Linux
自從服務(wù)器遷移以后,自定義的代碼倉(cāng)庫(kù)備份腳本一直沒(méi)有執(zhí)行過(guò),可是原來(lái)機(jī)器的環(huán)境已經(jīng)不存在了,只能自己摸索。雖然知道cron是用來(lái)實(shí)現(xiàn)定時(shí)任務(wù)的,但是一直不知道怎么做,今天終于出了結(jié)果......

自從服務(wù)器遷移以后,自定義的代碼倉(cāng)庫(kù)備份腳本一直沒(méi)有執(zhí)行過(guò),可是原來(lái)機(jī)器的環(huán)境已經(jīng)不存在了,只能自己摸索。雖然知道cron是用來(lái)實(shí)現(xiàn)定時(shí)任務(wù)的,但是一直不知道怎么做,今天終于出了結(jié)果,下面是我實(shí)現(xiàn)的方法(環(huán)境Ubuntu8.04)。

1. 使用crontab -e命令這個(gè)命令的使用比較簡(jiǎn)單。直接輸入

~# crontab -e

就會(huì)打開(kāi)一個(gè)編輯窗口,***行會(huì)有內(nèi)容格式的提示:

# m h dom mon dow command

具體意義表示:分鐘 小時(shí) 日期 月份 星期 命令,在某月(mon)的某天(dom)或者星期幾(dow)的幾點(diǎn)(h,24小時(shí)制)幾分(m)執(zhí)行某個(gè)命令(command),*表示任意時(shí)間。例如:3 * * * * /home/meng/hello.sh就是:每小時(shí)的03時(shí)執(zhí)行/home/meng/下的hello.sh腳本。

在保存之后,根據(jù)屏幕下面的提示輸入Ctrl+X退出,此時(shí)會(huì)提示是否保存,輸入Y;提示輸入文件名,并且有一個(gè)臨時(shí)的文件名,由于只是測(cè)試,直接回車(chē)保存。

注意:在完成編輯以后,要重新啟動(dòng)cron進(jìn)程:~# /etc/init.d/cron restart觀察運(yùn)行結(jié)果,會(huì)發(fā)現(xiàn)hello.sh會(huì)每隔一小時(shí),在03分時(shí)被執(zhí)行一次。

在使用這個(gè)命令時(shí),***的擔(dān)心就是在系統(tǒng)重啟以后是否還能順利執(zhí)行呢?我重啟系統(tǒng)以后發(fā)現(xiàn)一切正常,于是打消了這個(gè)顧慮。但是,仍然有一個(gè)問(wèn)題,一般情況下,服務(wù)器都是在重啟后處于登錄狀態(tài)下,并沒(méi)有用戶(hù)登入。那么如果我在執(zhí)行crontab -e命令時(shí),不是使用root賬戶(hù),那么在系統(tǒng)重啟之后是否還會(huì)順利執(zhí)行呢?

2. 編輯crontab文件crontab位于/ect/文件夾,在http://wiki.ubuntu.org.cn/CronHowto上有關(guān)于它的詳細(xì)介紹,但是我看的不是太懂。

打開(kāi)crontab文件,如果沒(méi)有編輯過(guò)可以看到如下類(lèi)似的內(nèi)容:

# /etc/crontab: system-wide crontab

# Unlike any other crontab you don't have to run the `crontab'

# command to install the new version when you edit this file

# and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do.

SHELL=/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command

17 ** * *   rootcd / && run-parts --report /etc/cron.hourly

25 6* * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )

47 6* * 7   roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )

52 61 * *   roottest -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

由于對(duì)腳本的認(rèn)知有限,不能詳細(xì)解釋每個(gè)命令的含義。在第10行,同樣定義了文件內(nèi)容的格式??梢钥吹奖仁褂胏rontab -e命令時(shí),多了一個(gè)user。它表示了執(zhí)行命令的用戶(hù),如果是root,就表明是系統(tǒng)用戶(hù)。于是,我加了如下一行:

3 * * * * root /home/meng/hello.sh

然后保存

【編輯推薦】

  1. Linux的自動(dòng)執(zhí)行程序cron和crontab
  2. Linux新手學(xué)堂 Crontab命令的實(shí)用方法
  3. Vixie Cron Crontab文件信息泄露漏洞
責(zé)任編輯:趙寧寧 來(lái)源: chinaitlab
相關(guān)推薦

2010-03-10 15:47:58

crontab定時(shí)任務(wù)

2022-08-15 15:43:29

Linuxcron

2024-07-29 08:08:30

2024-05-13 09:49:30

.NETQuartz庫(kù)Cron表達(dá)式

2012-02-07 13:31:14

SpringJava

2019-02-20 15:52:50

技術(shù)開(kāi)發(fā)代碼

2022-03-28 08:31:29

線程池定時(shí)任務(wù)

2022-11-11 14:55:14

Linuxcron

2024-11-04 16:01:01

2024-12-27 08:24:55

2010-01-07 13:38:41

Linux定時(shí)任務(wù)

2020-12-21 07:31:23

實(shí)現(xiàn)單機(jī)JDK

2023-12-11 09:50:35

Linux定時(shí)器

2019-02-25 15:44:16

開(kāi)源RabbitMQSpring Clou

2010-07-15 14:54:51

at命令crontab定時(shí)執(zhí)行任務(wù)

2023-12-19 08:09:06

Python定時(shí)任務(wù)Cron表達(dá)式

2021-12-16 14:25:03

Linux定時(shí)任務(wù)

2016-12-27 19:29:14

Linux命令定時(shí)任務(wù)

2021-04-16 13:20:41

ZeitLinux工具

2022-03-23 11:45:39

Quartz數(shù)據(jù)庫(kù)節(jié)點(diǎn)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)