最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Linux crontab定時(shí)任務(wù)配置方法(詳解)

 更新時(shí)間:2016年11月30日 10:32:39   投稿:jingxian  
下面小編就為大家?guī)硪黄狶inux crontab定時(shí)任務(wù)配置方法(詳解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

CRONTAB概念/介紹

crontab命令用于設(shè)置周期性被執(zhí)行的指令。該命令從標(biāo)準(zhǔn)輸入設(shè)備讀取指令,并將其存放于“crontab”文件中,以供之后讀取和執(zhí)行。

cron 系統(tǒng)調(diào)度進(jìn)程。 可以使用它在每天的非高峰負(fù)荷時(shí)間段運(yùn)行作業(yè),或在一周或一月中的不同時(shí)段運(yùn)行。cron是系統(tǒng)主要的調(diào)度進(jìn)程,可以在無需人工干預(yù)的情況下運(yùn)行作業(yè)。crontab命令允許用戶提交、編輯或刪除相應(yīng)的作業(yè)。每一個(gè)用戶都可以有一個(gè)crontab文件來保存調(diào)度信息。系統(tǒng)管理員可以通過cron.deny 和 cron.allow 這兩個(gè)文件來禁止或允許用戶擁有自己的crontab文件。

1: crontab文件一般位于/etc/下,這里面存放系統(tǒng)運(yùn)行的的調(diào)度程序。

[root@localhost cron]# more /etc/crontab

SHELL=/bin/bash

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

MAILTO=root

HOME=/

# run-parts

01 * * * * root run-parts /etc/cron.hourly

02 4 * * * root run-parts /etc/cron.daily

22 4 * * 0 root run-parts /etc/cron.weekly

42 4 1 * * root run-parts /etc/cron.monthly

2:每個(gè)用戶都會生成一個(gè)自動生成一個(gè)自己的crontab文件,一般位于/var/spool/cron目錄下

[root@localhost cron]# cd /var/spool/cron

[root@localhost cron]# ls

oracle root

如果你用命令crontab -r 就會刪除當(dāng)前用戶的crontab文件,例如你切換到oracle賬號下,執(zhí)行了該命令,那么/var/spool/cron/oracle文件就會刪除,如果要?jiǎng)?chuàng)建該文件只需要用crontab -e命令即可。注意,普通用戶一般沒有權(quán)限訪問/var/spool/cron

3:cron.deny 與 cron.allow文件

/etc/cron.deny 表示不能使用crontab 命令的用戶

/etc/cron.allow 表示能使用crontab的用戶。

默認(rèn)情況下,cron.allow文件不存在。如果兩個(gè)文件同時(shí)存在,那么/etc/cron.allow 優(yōu)先。如果兩個(gè)文件都不存在,那么只有超級用戶可以安排作業(yè)。

但是讓人納悶的是cron.deny文件是空的,如下所示

[oracle@localhost etc]$ more cron.deny

4:cron.hourly,cron.daily,cron.monthly,cron.weekly

[oracle@localhost etc]$ ls -lrt cron*

-rw-r--r-- 1 root root 255 Sep 21 2004 crontab

-rw-r--r-- 1 root root 0 May 16 2008 cron.deny

cron.hourly:

total 0

cron.monthly:

total 8

-rwxr-xr-x 1 root root 278 Sep 29 2004 0anacron

cron.weekly:

total 16

-rwxr-xr-x 1 root root 277 Sep 29 2004 0anacron

-rwxr-xr-x 1 root root 414 Jun 6 2007 00-makewhatis.cron

cron.daily:

total 60

-rwxr-xr-x 1 root root 286 Aug 14 2004 tmpwatch

-rwxr-xr-x 1 root root 276 Sep 29 2004 0anacron

-rwxr-xr-x 1 root root 2133 Dec 1 2004 prelink

-rwxr-xr-x 1 root root 180 May 2 2006 logrotate

-rwxr-xr-x 1 root root 418 Jun 6 2007 00-makewhatis.cron

-rwxr-xr-x 1 root root 104 Aug 2 2007 rpm

-rwxr-xr-x 1 root root 121 Aug 22 2007 slocate.cron

lrwxrwxrwx 1 root root 28 May 16 2008 00-logwatch -> ../log.d/scripts/logwatch.pl

cron.d:

total 12

-rw------- 1 root root 366 Jun 12 2007 sa-update

-rw-r--r-- 1 root root 188 Jul 18 2007 sysstat

CRONTAB在線手冊

注意:不同版本的Linux系統(tǒng),可能crontab手冊內(nèi)容有所出入,請以實(shí)際版本為準(zhǔn)。

[oracle@localhost ~]$ man crontab | more

CRONTAB(1)                             CRONTAB(1)



NAME
    crontab - maintain crontab files for individual users (ISC Cron V4.1)

SYNOPSIS
    crontab [-u user] file
    crontab [-u user] [-l | -r | -e] [-i] [-s]

DESCRIPTION
    Crontab is the program used to install, deinstall or list the tables
    used to drive the cron(8) daemon in ISC Cron. Each user can have their
    own crontab, and though these are files in /var/spool/ , they are not
    intended to be edited directly. For SELinux in mls mode can be even
    more crontabs - for each range. For more see selinux(8).

    If the cron.allow file exists, then you must be listed therein in order
    to be allowed to use this command. If the cron.allow file does not
    exist but the cron.deny file does exist, then you must not be listed in
    the cron.deny file in order to use this command. If neither of these
    files exists, only the super user will be allowed to use this command.


OPTIONS
    -u   It specifies the name of the user whose crontab is to be
       tweaked.  If this option is not given, crontab examines "your"
       crontab, i.e., the crontab of the person executing the command.
       Note that su(8) can confuse crontab and that if you are running
       inside of su(8) you should always use the -u option for safety's
       sake.  The first form of this command is used to install a new
       crontab from some named file or standard input if the pseudo-
       filename "-" is given.

    -l   The current crontab will be displayed on standard output.

    -r   The current crontab will be removed.

    -e   This option is used to edit the current crontab using the editor
       specified by the VISUAL or EDITOR environment variables.  After
       you exit from the editor, the modified crontab will be installed
       automatically.

    -i   This option modifies the -r option to prompt the user for a
       'y/Y' response before actually removing the crontab.

    -s   It will append the current SELinux security context string as an
       MLS_LEVEL setting to the crontab file before editing / replace-
       ment occurs - see the documentation of MLS_LEVEL in crontab(5).

SEE ALSO
    crontab(5), cron(8)

FILES
    /etc/cron.allow
    /etc/cron.deny

STANDARDS
    The crontab command conforms to IEEE Std1003.2-1992 (‘‘POSIX'').  This
    new command syntax differs from previous versions of Vixie Cron, as
    well as from the classic SVR3 syntax.

DIAGNOSTICS
    A fairly informative usage message appears if you run it with a bad
    command line.

AUTHOR
    Paul Vixie <vixie@isc.org>



4th Berkeley Distribution    16 Januar 2007           CRONTAB(1)

CRONTAB語法及應(yīng)用

1:查看當(dāng)前用戶的定時(shí)任務(wù)

[oracle@localhost ~]$ crontab -l

* * * * * /home/oracle/test.sh >/dev/null 2>&1

2:編輯當(dāng)前用戶的定時(shí)任務(wù)

可以在編輯狀態(tài)修改、刪除、新增一些定時(shí)任務(wù)。注釋一般用#

[oracle@localhost ~]$ crontab -e

3:刪除當(dāng)前用戶的定時(shí)任務(wù)

[root@localhost ~]# crontab -r

[root@localhost ~]# crontab -l

no crontab for root

4:

如下所示,一般crontab文件里面的定時(shí)任務(wù)格式如下所示:

59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2>&1

crontab 文件中每個(gè)條目中各個(gè)域的意義和格式:

第一列 分鐘: 1——59

第二列 小時(shí): 1——23(0表示子夜)

第三列 日 : 1——31

第四列 月 : 1——12

第五列 星期: 星期0——6(0表示星期天,1表示星期一、以此類推)

第六列 要運(yùn)行的命令

我們暫且用C1、C2、C3、C4、C5、C6代表這六列,前面五列通過組合方式來決定執(zhí)行腳本的頻率,最小頻率為每分鐘執(zhí)行一次,其中Cn可以用 * ; */n ; T1-T2; a,b,c; 四種形式來表示:

當(dāng) C1 為 * 時(shí)表示每分鐘都要執(zhí)行腳本,C2 為 * 時(shí)表示每小時(shí)都要執(zhí)行程式,依次類推.....

當(dāng) C1 為 T1-T2 時(shí)表示從第 T1 分鐘到第 T2 分鐘這段時(shí)間內(nèi)要執(zhí)行,C2 為 T1-T2 時(shí)表示從第 T1 到第 T2 小時(shí)都要執(zhí)行,依次類推....

當(dāng) C1 為 */n 時(shí)表示每 n 分鐘的時(shí)間間隔執(zhí)行一次,C2 為 */n 表示每隔n小時(shí)的間隔執(zhí)行一次,依次類推.....

當(dāng) C1 為 a, b, c,... 時(shí)表示第 a, b, c,... 分鐘要執(zhí)行,C2 為 a, b, c,... 時(shí)表示第 a, b, c...個(gè)小時(shí)要執(zhí)行,依次類推....

下面列舉幾個(gè)例子供大家參考

1: 59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2>&1

表示每天23點(diǎn)59分執(zhí)行腳本/home/oracle/scripts/alert_log_archive.sh

2: */5 * * * * /home/oracle/scripts/monitoring_alert_log.sh >/dev/null 2>&1

表示每5分鐘執(zhí)行一次腳本/home/oracle/scripts/monitoring_alert_log.sh

3: 0 20 * * 1-5 mail -s "**********" kerry@domain.name < /tmp/maildata

周一到周五每天下午 20:00 寄一封信給 kerry@domain.name

..............................................

關(guān)于 >/dev/null 2>&1 的解釋:

0表示鍵盤輸入

1表示標(biāo)準(zhǔn)輸出

2表示錯(cuò)誤輸出.

我們首先創(chuàng)建test.sh腳本如下:

#! /bin/sh

echo "hello, everybody, now is " `date`

date >> test.txt

然后添加作業(yè)

* * * * * /home/oracle/test.sh >/home/oracle/log.txt & 默認(rèn)值為1,即和下面命令一致

* * * * * /home/oracle/test.sh 1>/home/oracle/log.txt &

* * * * * /home/oracle/test.sh 2>/home/oracle/log.txt &

* * * * * /home/oracle/test.sh 2>/home/oracle/log.txt 2>&1 &

1,2將tesh.sh 命令輸出重定向到log.txt, 即輸出內(nèi)容不打印到屏幕上,而是輸出到log.txt文件中。如果你需要追加而不是覆蓋,可以用 >>代替>

2>&1 是將錯(cuò)誤輸出重定向到標(biāo)準(zhǔn)輸出。 然后將標(biāo)準(zhǔn)輸入重定向到文件log.txt。

&1 表示的是文件描述1,表示標(biāo)準(zhǔn)輸出,如果這里少了&就成了數(shù)字1,就表示重定向到文件1。

注意事項(xiàng):

配置定時(shí)任務(wù)時(shí),需要注意兩個(gè)問題:

1: 在SHELL中設(shè)置了必要的環(huán)境變量;例如一個(gè)shell腳本手工執(zhí)行OK,但是配置成后臺作業(yè)執(zhí)行時(shí),獲取不到ORACLE的環(huán)境變量,這是因?yàn)閏rontab環(huán)境變量問題,Crontab的環(huán)境默認(rèn)情況下并不包含系統(tǒng)中當(dāng)前用戶的環(huán)境。所以,你需要在shell腳本中添加必要的環(huán)境變量的設(shè)置

2: 盡量所有的文件都采用完全路徑方式,避免使用相對路徑。

以上這篇Linux crontab定時(shí)任務(wù)配置方法(詳解)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Linux內(nèi)核設(shè)備驅(qū)動之內(nèi)存管理筆記整理

    Linux內(nèi)核設(shè)備驅(qū)動之內(nèi)存管理筆記整理

    今天小編就為大家分享一篇關(guān)于Linux內(nèi)核設(shè)備驅(qū)動之內(nèi)存管理筆記整理,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • CentOS6.9下NFS服務(wù)安裝配置教程

    CentOS6.9下NFS服務(wù)安裝配置教程

    這篇文章主要為大家詳細(xì)介紹了CentOS6.9下NFS服務(wù)安裝配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • centos7 無線網(wǎng)卡驅(qū)動的安裝及無線網(wǎng)絡(luò)的配置詳解

    centos7 無線網(wǎng)卡驅(qū)動的安裝及無線網(wǎng)絡(luò)的配置詳解

    本篇文章主要介紹了centos7 無線網(wǎng)卡驅(qū)動的安裝及無線網(wǎng)絡(luò)的配置詳解,具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-03-03
  • Linux上進(jìn)行常用軟件的配置方法

    Linux上進(jìn)行常用軟件的配置方法

    這篇文章主要介紹了Linux上進(jìn)行常用軟件的配置方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • PHP程序員玩轉(zhuǎn)Linux系列 Linux和Windows安裝nginx

    PHP程序員玩轉(zhuǎn)Linux系列 Linux和Windows安裝nginx

    這篇文章主要為大家詳細(xì)介紹了PHP程序員玩轉(zhuǎn)Linux系列文章,Linux和Windows安裝nginx教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Kali?Linux靜態(tài)IP的設(shè)置指南

    Kali?Linux靜態(tài)IP的設(shè)置指南

    在?Kali?Linux?中設(shè)置靜態(tài)?IP?地址是一個(gè)常見的需求,尤其是在進(jìn)行滲透測試或者需要長期穩(wěn)定連接的情況下,本文將指導(dǎo)你如何在?Kali?Linux?中配置靜態(tài)?IP?地址,感興趣的小伙伴跟著小編一起來看看吧
    2024-12-12
  • 圖解linux安裝tomcat(附常用命令)

    圖解linux安裝tomcat(附常用命令)

    這篇文章主要以圖片文字結(jié)合的方式為大家介紹了linux安裝tomcat,并linux操作tomcat一些常用命令,感興趣的小伙伴們可以參考一下
    2016-01-01
  • Yum安裝中出現(xiàn)錯(cuò)誤mirrorlist.txt的解決方法

    Yum安裝中出現(xiàn)錯(cuò)誤mirrorlist.txt的解決方法

    前幾天在使用Yum install命令安裝軟件的時(shí)候一直提示一個(gè)mirrorlist.txt錯(cuò)誤,通過查找相關(guān)的資料現(xiàn)在找到了解決的方法,所以這篇文章就整理出來和大家分享一下,有同樣遇到這個(gè)問題的朋友們可以參考借鑒下。
    2016-10-10
  • 新手學(xué)習(xí)Linux系統(tǒng)的11點(diǎn)建議

    新手學(xué)習(xí)Linux系統(tǒng)的11點(diǎn)建議

    這篇文章主要為大家詳細(xì)介紹了新手學(xué)習(xí)Linux系統(tǒng)的11點(diǎn)建議,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • CentOS7使用dnf安裝mysql的方法

    CentOS7使用dnf安裝mysql的方法

    本篇文章主要介紹了CentOS7使用dnf安裝mysql的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03

最新評論

张掖市| 镇平县| 岗巴县| 安西县| 乌什县| 绥阳县| 肃南| 时尚| 兰考县| 营口市| 天峻县| 宁河县| 临夏市| 仪征市| 静海县| 东山县| 顺义区| 桑植县| 墨竹工卡县| 五家渠市| 秭归县| 岳普湖县| 宜宾县| 宁夏| 灌云县| 乃东县| 晋城| 巴林右旗| 威信县| 新宁县| 东丰县| 曲周县| 溆浦县| 伊金霍洛旗| 华容县| 南郑县| 平泉县| 新建县| 天气| 翼城县| 龙海市|