LINUX自動運行程序怎么設(shè)置
LINUX自動運行程序怎么設(shè)置
這里學(xué)習(xí)啦小編介紹Linux中的cron命令和at命令,來設(shè)置LINUX自動運行程序。但是一些命令知識并不清楚,所以學(xué)習(xí)啦小編來幫助大家提升LINUX操作系統(tǒng)的命令知識,歡迎大家來閱讀!!!
LINUX自動運行程序怎么設(shè)置
crontab文件的存放路徑是/etc/crontab
cron用來執(zhí)行周期性的事件,cron命令有個一個特殊的文件與之對應(yīng),內(nèi)容如下
[oracle@golonglee spool]$ cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# 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
# | | | | |
# * * * * * user-name command to be executed
[oracle@golonglee spool]$
Linux的啟動模式可通過inittab文件進(jìn)行配置,下面是inittab文件的內(nèi)容
# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
# 這里的【id:5:initdefault:】就是說本系統(tǒng)默認(rèn)是以X11也就是x-window的模式啟動。
Runlevel 0 ——init關(guān)閉所有進(jìn)程并終止系統(tǒng)。
Runlevel 1 ——轉(zhuǎn)到單用戶模式
Runlevel 2 ——進(jìn)入多用戶的模式
Runlevel 3 ——多用戶模式,也是多數(shù)服務(wù)器的默認(rèn)模式。
Runlevel 4 —— 一般不使用,可以實現(xiàn)一些特定的登錄請求。
Runlevel 5 ——X Window終端。
Runlevel 6 ——是關(guān)閉進(jìn)程并重新啟動系統(tǒng)。
/etc/rc開頭的文件,一般都是系統(tǒng)啟動后自動執(zhí)行的文件。rc開頭的文件很多,如下:
rc rc1.d/ rc3.d/ rc5.d/ rc.d/ rc.sysinit
rc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local
其中init是所有進(jìn)程之父 init讀取/etc/inittab,執(zhí)行rc.sysinit腳本
運行順序由inittab中設(shè)置的init tree決定,一般設(shè)置為: /etc/rc.d/rc0.d /etc/rc.d/rc1.d /etc/rc.d/rc2.d /etc/rc.d/rc3.d /etc/rc.d/rc4.d /etc/rc.d/rc5.d /etc/rc.d/rc6.d /etc/rc.d/rc.local
其中/etc/rc.d/rc.local默認(rèn)是用戶自定義的腳本
/etc/rc.d/rc.local文件內(nèi)容如下:
[root@golonglee etc]# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
經(jīng)常使用的 rc.local 則完全是習(xí)慣問題,不是標(biāo)準(zhǔn)。不過使用 rc.local是個好習(xí)慣。