第二部分 Linux Shell高级编程技巧——第三章 运行级别脚本介绍
笔记
#运行级别脚本介绍
#准备工作
#进入目录
cd /home/wgb/shell
#建立文件夹
mkdir 0421
#进入目录
cd 0421#运行级别
#运行级别目录
#进入etc目录
[root@localhost etc]# cd /etc
#ls rc后按tab键,显示rc开头的文件或者目录
[root@localhost etc]# ls rc
rc rc.news rc1.d rc4.d
rc.d rc.sysinit rc2.d rc5.d
rc.local rc0.d rc3.d rc6.d
#获得当前运行级别
[root@localhost etc]# runlevel
N 5
#进入目录
[root@localhost etc]# cd rc5.d
#显示内容
[root@localhost rc5.d]# ls
K05innd K50snmpd S09isdn
K05saslauthd K50snmptrapd S10network
K09privoxy K50tux S12syslog
K10psacct K50vsftpd S13irqbalance
K12mailman K54pxe S13portmap
K15httpd K55routed S14nfslock
K15postgresql K61ldap S17keytable
K16rarpd K65identd S20random
K20bootparamd K65kadmin S24pcmcia
K20iscsi K65kprop S25netfs
K20netdump-server K65krb524 S26apmd
K20nfs K65krb5kdc S28autofs
K20rstatd K70aep1000 S55sshd
K20rusersd K70bcm5820 S56rawdevices
K20rwalld K74ntpd S56xinetd
K20rwhod K74ups S59hpoj
K24irda K74ypserv S80sendmail
K25squid K74ypxfrd S80spamassassin
K28amd K84bgpd S85gpm
K34dhcrelay K84ospf6d S90FreeWnn
K34yppasswdd K84ospfd S90canna
K35atalk K84ripd S90crond
K35dhcpd K84ripngd S90cups
K35vncserver K85zebra S90xfs
K35winbind K90isicom S91smb
K36lisa K95firstboot S95anacron
K40mars-nwe S00microcode_ctl S95atd
K45arpwatch S03vmware-tools S95jexec
K45named S05kudzu S97rhnsd
K45smartd S08ip6tables S99local
K46radvd S08ipchains S99mdmonitor
K50netdump S08iptables
#S和K表示当前级别下的脚本 S:被启动 K:被终止
#列出详细信息,指向init.d目录下的对应文件
[root@localhost rc5.d]# ls -al
total 8
drwxr-xr-x 2 root root 4096 Nov 26 09:42 .
drwxr-xr-x 10 root root 4096 Nov 24 10:38 ..
lrwxrwxrwx 1 root root 14 Sep 21 2011 K05innd -> ../init.d/innd
lrwxrwxrwx 1 root root 19 Sep 21 2011 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx 1 root root 17 Sep 21 2011 K09privoxy -> ../init.d/privoxy
lrwxrwxrwx 1 root root 16 Sep 21 2011 K10psacct -> ../init.d/psacct
lrwxrwxrwx 1 root root 17 Sep 21 2011 K12mailman -> ../init.d/mailman
lrwxrwxrwx 1 root root 15 Sep 21 2011 K15httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 20 Sep 21 2011 K15postgresql -> ../init.d/postgresql
lrwxrwxrwx 1 root root 15 Sep 21 2011 K16rarpd -> ../init.d/rarpd
lrwxrwxrwx 1 root root 20 Sep 21 2011 K20bootparamd -> ../init.d/bootparamd
lrwxrwxrwx 1 root root 15 Sep 21 2011 K20iscsi -> ../init.d/iscsi
lrwxrwxrwx 1 root root 24 Sep 21 2011 K20netdump-server -> ../init.d/netdump-server
lrwxrwxrwx 1 root root 13 Sep 21 2011 K20nfs -> ../init.d/nfs
lrwxrwxrwx 1 root root 16 Sep 21 2011 K20rstatd -> ../init.d/rstatd
lrwxrwxrwx 1 root root 17 Sep 21 2011 K20rusersd -> ../init.d/rusersd
lrwxrwxrwx 1 root root 16 Sep 21 2011 K20rwalld -> ../init.d/rwalld
lrwxrwxrwx 1 root root 15 Sep 21 2011 K20rwhod -> ../init.d/rwhod
lrwxrwxrwx 1 root root 14 Sep 21 2011 K24irda -> ../init.d/irda
lrwxrwxrwx 1 root root 15 Sep 21 2011 K25squid -> ../init.d/squid
lrwxrwxrwx 1 root root 13 Sep 21 2011 K28amd -> ../init.d/amd
lrwxrwxrwx 1 root root 18 Sep 21 2011 K34dhcrelay -> ../init.d/dhcrelay
lrwxrwxrwx 1 root root 19 Sep 21 2011 K34yppasswdd -> ../init.d/yppasswdd
lrwxrwxrwx 1 root root 15 Sep 21 2011 K35atalk -> ../init.d/atalk
lrwxrwxrwx 1 root root 15 Sep 21 2011 K35dhcpd -> ../init.d/dhcpd
lrwxrwxrwx 1 root root 19 Sep 21 2011 K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 17 Sep 21 2011 K35winbind -> ../init.d/winbind
lrwxrwxrwx 1 root root 14 Sep 21 2011 K36lisa -> ../init.d/lisa
lrwxrwxrwx 1 root root 18 Sep 21 2011 K40mars-nwe -> ../init.d/mars-nwe
lrwxrwxrwx 1 root root 18 Sep 21 2011 K45arpwatch -> ../init.d/arpwatch
lrwxrwxrwx 1 root root 15 Sep 21 2011 K45named -> ../init.d/named
lrwxrwxrwx 1 root root 16 Sep 21 2011 K45smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 15 Sep 21 2011 K46radvd -> ../init.d/radvd
lrwxrwxrwx 1 root root 17 Sep 21 2011 K50netdump -> ../init.d/netdump
lrwxrwxrwx 1 root root 15 Sep 21 2011 K50snmpd -> ../init.d/snmpd
lrwxrwxrwx 1 root root 19 Sep 21 2011 K50snmptrapd -> ../init.d/snmptrapd
lrwxrwxrwx 1 root root 13 Sep 21 2011 K50tux -> ../init.d/tux
lrwxrwxrwx 1 root root 16 Sep 21 2011 K50vsftpd -> ../init.d/vsftpd
lrwxrwxrwx 1 root root 13 Sep 21 2011 K54pxe -> ../init.d/pxe
lrwxrwxrwx 1 root root 16 Sep 21 2011 K55routed -> ../init.d/routed
lrwxrwxrwx 1 root root 14 Sep 21 2011 K61ldap -> ../init.d/ldap
lrwxrwxrwx 1 root root 16 Sep 21 2011 K65identd -> ../init.d/identd
lrwxrwxrwx 1 root root 16 Sep 21 2011 K65kadmin -> ../init.d/kadmin
lrwxrwxrwx 1 root root 15 Sep 21 2011 K65kprop -> ../init.d/kprop
lrwxrwxrwx 1 root root 16 Sep 21 2011 K65krb524 -> ../init.d/krb524
lrwxrwxrwx 1 root root 17 Sep 21 2011 K65krb5kdc -> ../init.d/krb5kdc
lrwxrwxrwx 1 root root 17 Sep 21 2011 K70aep1000 -> ../init.d/aep1000
lrwxrwxrwx 1 root root 17 Sep 21 2011 K70bcm5820 -> ../init.d/bcm5820
lrwxrwxrwx 1 root root 14 Sep 21 2011 K74ntpd -> ../init.d/ntpd
lrwxrwxrwx 1 root root 13 Sep 21 2011 K74ups -> ../init.d/ups
lrwxrwxrwx 1 root root 16 Sep 21 2011 K74ypserv -> ../init.d/ypserv
lrwxrwxrwx 1 root root 16 Sep 21 2011 K74ypxfrd -> ../init.d/ypxfrd
lrwxrwxrwx 1 root root 14 Sep 21 2011 K84bgpd -> ../init.d/bgpd
lrwxrwxrwx 1 root root 16 Sep 21 2011 K84ospf6d -> ../init.d/ospf6d
lrwxrwxrwx 1 root root 15 Sep 21 2011 K84ospfd -> ../init.d/ospfd
lrwxrwxrwx 1 root root 14 Sep 21 2011 K84ripd -> ../init.d/ripd
lrwxrwxrwx 1 root root 16 Sep 21 2011 K84ripngd -> ../init.d/ripngd
lrwxrwxrwx 1 root root 15 Sep 21 2011 K85zebra -> ../init.d/zebra
lrwxrwxrwx 1 root root 16 Sep 21 2011 K90isicom -> ../init.d/isicom
lrwxrwxrwx 1 root root 19 Sep 21 2011 K95firstboot -> ../init.d/firstboot
lrwxrwxrwx 1 root root 23 Sep 21 2011 S00microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx 1 root root 22 Oct 19 2012 S03vmware-tools -> ../init.d/vmware-tools
lrwxrwxrwx 1 root root 15 Sep 21 2011 S05kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 19 Sep 21 2011 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 Sep 21 2011 S08ipchains -> ../init.d/ipchains
lrwxrwxrwx 1 root root 18 Sep 21 2011 S08iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 14 Sep 21 2011 S09isdn -> ../init.d/isdn
lrwxrwxrwx 1 root root 17 Sep 21 2011 S10network -> ../init.d/network
lrwxrwxrwx 1 root root 16 Sep 21 2011 S12syslog -> ../init.d/syslog
lrwxrwxrwx 1 root root 20 Sep 21 2011 S13irqbalance -> ../init.d/irqbalance
lrwxrwxrwx 1 root root 17 Sep 21 2011 S13portmap -> ../init.d/portmap
lrwxrwxrwx 1 root root 17 Sep 21 2011 S14nfslock -> ../init.d/nfslock
lrwxrwxrwx 1 root root 18 Sep 21 2011 S17keytable -> ../init.d/keytable
lrwxrwxrwx 1 root root 16 Sep 21 2011 S20random -> ../init.d/random
lrwxrwxrwx 1 root root 16 Sep 21 2011 S24pcmcia -> ../init.d/pcmcia
lrwxrwxrwx 1 root root 15 Sep 21 2011 S25netfs -> ../init.d/netfs
lrwxrwxrwx 1 root root 14 Sep 21 2011 S26apmd -> ../init.d/apmd
lrwxrwxrwx 1 root root 16 Sep 21 2011 S28autofs -> ../init.d/autofs
lrwxrwxrwx 1 root root 14 Sep 21 2011 S55sshd -> ../init.d/sshd
lrwxrwxrwx 1 root root 20 Sep 21 2011 S56rawdevices -> ../init.d/rawdevices
lrwxrwxrwx 1 root root 16 Sep 21 2011 S56xinetd -> ../init.d/xinetd
lrwxrwxrwx 1 root root 14 Sep 21 2011 S59hpoj -> ../init.d/hpoj
lrwxrwxrwx 1 root root 18 Sep 21 2011 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx 1 root root 22 Sep 21 2011 S80spamassassin -> ../init.d/spamassassin
lrwxrwxrwx 1 root root 13 Sep 21 2011 S85gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root 17 Sep 21 2011 S90FreeWnn -> ../init.d/FreeWnn
lrwxrwxrwx 1 root root 15 Sep 21 2011 S90canna -> ../init.d/canna
lrwxrwxrwx 1 root root 15 Sep 21 2011 S90crond -> ../init.d/crond
lrwxrwxrwx 1 root root 14 Sep 21 2011 S90cups -> ../init.d/cups
lrwxrwxrwx 1 root root 13 Sep 21 2011 S90xfs -> ../init.d/xfs
lrwxrwxrwx 1 root root 13 Sep 21 2011 S91smb -> ../init.d/smb
lrwxrwxrwx 1 root root 17 Sep 21 2011 S95anacron -> ../init.d/anacron
lrwxrwxrwx 1 root root 13 Sep 21 2011 S95atd -> ../init.d/atd
lrwxrwxrwx 1 root root 15 Nov 19 20:42 S95jexec -> ../init.d/jexec
lrwxrwxrwx 1 root root 15 Sep 21 2011 S97rhnsd -> ../init.d/rhnsd
lrwxrwxrwx 1 root root 11 Sep 8 2007 S99local -> ../rc.local
lrwxrwxrwx 1 root root 19 Sep 21 2011 S99mdmonitor -> ../init.d/mdmonitor
#进入rc3.d目录
[root@localhost rc5.d]# cd ../rc3.d
#列出详细信息
[root@localhost rc3.d]# ls -al
total 8
drwxr-xr-x 2 root root 4096 Nov 26 09:42 .
drwxr-xr-x 10 root root 4096 Nov 24 10:38 ..
lrwxrwxrwx 1 root root 14 Sep 8 2007 K05innd -> ../init.d/innd
lrwxrwxrwx 1 root root 19 Sep 8 2007 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx 1 root root 17 Sep 8 2007 K09privoxy -> ../init.d/privoxy
lrwxrwxrwx 1 root root 16 Sep 8 2007 K10psacct -> ../init.d/psacct
lrwxrwxrwx 1 root root 17 Sep 8 2007 K12mailman -> ../init.d/mailman
lrwxrwxrwx 1 root root 15 Sep 8 2007 K15httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 20 Sep 8 2007 K15postgresql -> ../init.d/postgresql
lrwxrwxrwx 1 root root 15 Sep 8 2007 K16rarpd -> ../init.d/rarpd
lrwxrwxrwx 1 root root 20 Sep 8 2007 K20bootparamd -> ../init.d/bootparamd
lrwxrwxrwx 1 root root 15 Sep 8 2007 K20iscsi -> ../init.d/iscsi
lrwxrwxrwx 1 root root 24 Sep 8 2007 K20netdump-server -> ../init.d/netdump-server
lrwxrwxrwx 1 root root 13 Sep 8 2007 K20nfs -> ../init.d/nfs
lrwxrwxrwx 1 root root 16 Sep 8 2007 K20rstatd -> ../init.d/rstatd
lrwxrwxrwx 1 root root 17 Sep 8 2007 K20rusersd -> ../init.d/rusersd
lrwxrwxrwx 1 root root 16 Sep 8 2007 K20rwalld -> ../init.d/rwalld
lrwxrwxrwx 1 root root 15 Sep 8 2007 K20rwhod -> ../init.d/rwhod
lrwxrwxrwx 1 root root 14 Sep 8 2007 K24irda -> ../init.d/irda
lrwxrwxrwx 1 root root 15 Sep 8 2007 K25squid -> ../init.d/squid
lrwxrwxrwx 1 root root 13 Sep 8 2007 K28amd -> ../init.d/amd
lrwxrwxrwx 1 root root 18 Sep 8 2007 K34dhcrelay -> ../init.d/dhcrelay
lrwxrwxrwx 1 root root 19 Sep 8 2007 K34yppasswdd -> ../init.d/yppasswdd
lrwxrwxrwx 1 root root 15 Sep 8 2007 K35atalk -> ../init.d/atalk
lrwxrwxrwx 1 root root 15 Sep 8 2007 K35dhcpd -> ../init.d/dhcpd
lrwxrwxrwx 1 root root 13 Sep 8 2007 K35smb -> ../init.d/smb
lrwxrwxrwx 1 root root 19 Sep 8 2007 K35vncserver -> ../init.d/vncserver
lrwxrwxrwx 1 root root 17 Sep 8 2007 K35winbind -> ../init.d/winbind
lrwxrwxrwx 1 root root 14 Sep 8 2007 K36lisa -> ../init.d/lisa
lrwxrwxrwx 1 root root 18 Sep 8 2007 K40mars-nwe -> ../init.d/mars-nwe
lrwxrwxrwx 1 root root 18 Sep 8 2007 K45arpwatch -> ../init.d/arpwatch
lrwxrwxrwx 1 root root 15 Sep 8 2007 K45named -> ../init.d/named
lrwxrwxrwx 1 root root 16 Sep 8 2007 K45smartd -> ../init.d/smartd
lrwxrwxrwx 1 root root 15 Sep 8 2007 K46radvd -> ../init.d/radvd
lrwxrwxrwx 1 root root 17 Sep 8 2007 K50netdump -> ../init.d/netdump
lrwxrwxrwx 1 root root 15 Sep 8 2007 K50snmpd -> ../init.d/snmpd
lrwxrwxrwx 1 root root 19 Sep 8 2007 K50snmptrapd -> ../init.d/snmptrapd
lrwxrwxrwx 1 root root 13 Sep 8 2007 K50tux -> ../init.d/tux
lrwxrwxrwx 1 root root 16 Sep 8 2007 K50vsftpd -> ../init.d/vsftpd
lrwxrwxrwx 1 root root 13 Sep 8 2007 K54pxe -> ../init.d/pxe
lrwxrwxrwx 1 root root 16 Sep 8 2007 K55routed -> ../init.d/routed
lrwxrwxrwx 1 root root 14 Sep 8 2007 K61ldap -> ../init.d/ldap
lrwxrwxrwx 1 root root 16 Sep 8 2007 K65identd -> ../init.d/identd
lrwxrwxrwx 1 root root 16 Sep 8 2007 K65kadmin -> ../init.d/kadmin
lrwxrwxrwx 1 root root 15 Sep 8 2007 K65kprop -> ../init.d/kprop
lrwxrwxrwx 1 root root 16 Sep 8 2007 K65krb524 -> ../init.d/krb524
lrwxrwxrwx 1 root root 17 Sep 8 2007 K65krb5kdc -> ../init.d/krb5kdc
lrwxrwxrwx 1 root root 17 Sep 8 2007 K70aep1000 -> ../init.d/aep1000
lrwxrwxrwx 1 root root 17 Sep 8 2007 K70bcm5820 -> ../init.d/bcm5820
lrwxrwxrwx 1 root root 14 Sep 7 2007 K74ntpd -> ../init.d/ntpd
lrwxrwxrwx 1 root root 13 Sep 8 2007 K74ups -> ../init.d/ups
lrwxrwxrwx 1 root root 16 Sep 8 2007 K74ypserv -> ../init.d/ypserv
lrwxrwxrwx 1 root root 16 Sep 8 2007 K74ypxfrd -> ../init.d/ypxfrd
lrwxrwxrwx 1 root root 14 Sep 8 2007 K84bgpd -> ../init.d/bgpd
lrwxrwxrwx 1 root root 16 Sep 8 2007 K84ospf6d -> ../init.d/ospf6d
lrwxrwxrwx 1 root root 15 Sep 8 2007 K84ospfd -> ../init.d/ospfd
lrwxrwxrwx 1 root root 14 Sep 8 2007 K84ripd -> ../init.d/ripd
lrwxrwxrwx 1 root root 16 Sep 8 2007 K84ripngd -> ../init.d/ripngd
lrwxrwxrwx 1 root root 15 Sep 8 2007 K85zebra -> ../init.d/zebra
lrwxrwxrwx 1 root root 16 Sep 8 2007 K90isicom -> ../init.d/isicom
lrwxrwxrwx 1 root root 19 Sep 7 2007 K95firstboot -> ../init.d/firstboot
lrwxrwxrwx 1 root root 23 Sep 8 2007 S00microcode_ctl -> ../init.d/microcode_ctl
lrwxrwxrwx 1 root root 22 Oct 19 2012 S03vmware-tools -> ../init.d/vmware-tools
lrwxrwxrwx 1 root root 15 Sep 8 2007 S05kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 19 Sep 8 2007 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 Sep 8 2007 S08ipchains -> ../init.d/ipchains
lrwxrwxrwx 1 root root 18 Sep 8 2007 S08iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 14 Sep 8 2007 S09isdn -> ../init.d/isdn
lrwxrwxrwx 1 root root 17 Sep 8 2007 S10network -> ../init.d/network
lrwxrwxrwx 1 root root 16 Sep 8 2007 S12syslog -> ../init.d/syslog
lrwxrwxrwx 1 root root 20 Sep 8 2007 S13irqbalance -> ../init.d/irqbalance
lrwxrwxrwx 1 root root 17 Sep 8 2007 S13portmap -> ../init.d/portmap
lrwxrwxrwx 1 root root 17 Sep 8 2007 S14nfslock -> ../init.d/nfslock
lrwxrwxrwx 1 root root 18 Sep 8 2007 S17keytable -> ../init.d/keytable
lrwxrwxrwx 1 root root 16 Sep 8 2007 S20random -> ../init.d/random
lrwxrwxrwx 1 root root 16 Sep 8 2007 S24pcmcia -> ../init.d/pcmcia
lrwxrwxrwx 1 root root 15 Sep 8 2007 S25netfs -> ../init.d/netfs
lrwxrwxrwx 1 root root 14 Sep 8 2007 S26apmd -> ../init.d/apmd
lrwxrwxrwx 1 root root 16 Sep 8 2007 S28autofs -> ../init.d/autofs
lrwxrwxrwx 1 root root 14 Sep 8 2007 S55sshd -> ../init.d/sshd
lrwxrwxrwx 1 root root 20 Sep 8 2007 S56rawdevices -> ../init.d/rawdevices
lrwxrwxrwx 1 root root 16 Sep 8 2007 S56xinetd -> ../init.d/xinetd
lrwxrwxrwx 1 root root 14 Sep 8 2007 S59hpoj -> ../init.d/hpoj
lrwxrwxrwx 1 root root 18 Sep 8 2007 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx 1 root root 22 Sep 8 2007 S80spamassassin -> ../init.d/spamassassin
lrwxrwxrwx 1 root root 13 Sep 8 2007 S85gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root 17 Sep 8 2007 S90FreeWnn -> ../init.d/FreeWnn
lrwxrwxrwx 1 root root 15 Sep 8 2007 S90canna -> ../init.d/canna
lrwxrwxrwx 1 root root 15 Sep 8 2007 S90crond -> ../init.d/crond
lrwxrwxrwx 1 root root 14 Sep 8 2007 S90cups -> ../init.d/cups
lrwxrwxrwx 1 root root 13 Sep 8 2007 S90xfs -> ../init.d/xfs
lrwxrwxrwx 1 root root 17 Sep 8 2007 S95anacron -> ../init.d/anacron
lrwxrwxrwx 1 root root 13 Sep 8 2007 S95atd -> ../init.d/atd
lrwxrwxrwx 1 root root 15 Nov 19 20:42 S95jexec -> ../init.d/jexec
lrwxrwxrwx 1 root root 15 Sep 8 2007 S97rhnsd -> ../init.d/rhnsd
lrwxrwxrwx 1 root root 11 Sep 8 2007 S99local -> ../rc.local
lrwxrwxrwx 1 root root 19 Sep 8 2007 S99mdmonitor -> ../init.d/mdmonitor
#阿拉伯数字小先启动,大后启动# inittab
#查看inittab文件内容
[root@localhost etc]# cat inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
## Default runlevel. The runlevels used by RHS 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:# System initialization.
si::sysinit:/etc/rc.d/rc.sysinitl0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm –nodaemon
#作为服务器:默认为3
#学会查看帮助信息
#再次查看inittab文件
[root@localhost etc]# cat inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
## Default runlevel. The runlevels used by RHS 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:# System initialization.
si::sysinit:/etc/rc.d/rc.sysinitl0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6# Things to run in every runlevel
ud:once:/sbin/update
#更改的内容
#checkdisk::once:/sbin/checkdisk.sh > /dev/console 2>&1
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm -nodaemon#启动应用程序
#启动脚本分析
#编辑文件
[root@localhost rc3.d]# vi S90crond
#查看文件内容
[root@localhost rc3.d]# cat S90crond
#! /bin/bash
#
# crond Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
# programs at periodic scheduled times. vixie cron adds a \
# number of features to the basic UNIX cron, including better \
# security and more powerful configuration options.
# processname: crond
# config: /etc/crontab
# pidfile: /var/run/crond.pid# Source function library.
. /etc/init.d/functionsRETVAL=0# See how we were called.prog="crond"start() {echo -n $"Starting $prog: "daemon crondRETVAL=$?echo[ $RETVAL -eq 0 ] && touch /var/lock/subsys/crondreturn $RETVAL
}stop() {echo -n $"Stopping $prog: "killproc crondRETVAL=$?echo[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/crondreturn $RETVAL
}rhstatus() {status crond
}restart() {stopstart
}reload() {echo -n $"Reloading cron daemon configuration: "killproc crond -HUPretval=$?echoreturn $RETVAL
}case "$1" instart)start;;stop)stop;;restart)restart;;reload)reload;;status)rhstatus;;condrestart)[ -f /var/lock/subsys/crond ] && restart || :;;*)echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"exit 1
esacexit $?
#启动脚本
service server start|stop|restart|…
srcipt_name start|stop|restart
#停止crond服务
[root@localhost rc3.d]# service crond stop
Stopping crond: [ OK ]
#启动crond服务
[root@localhost rc3.d]# service crond start
Starting crond: ^[[A [ OK ]
#重启crond服务
[root@localhost rc3.d]# service crond restart
Stopping crond: [ OK ]
Starting crond: [ OK ]
#查看crond服务状态
[root@localhost rc3.d]# service crond status
crond (pid 3737) is running...
#进入inti.d目录
[root@localhost rc3.d]# cd ../init.d/
#列出所有内容
[root@localhost init.d]# ls
FreeWnn gpm krb5kdc portmap smartd
aep1000 halt kudzu postfix smb
amd hpoj ldap postgresql snmpd
anacron httpd lisa privoxy snmptrapd
apmd identd lpd psacct spamassassin
arpwatch innd mailman pxe squid
atalk ip6tables mars-nwe radvd sshd
atd ipchains mdmonitor random syslog
autofs iptables microcode_ctl rarpd tux
bcm5820 irda named rawdevices ups
bgpd irqbalance netdump rhnsd vmware-tools
bluetooth iscsi netdump-server ripd vncserver
bootparamd isdn netfs ripngd vsftpd
canna isicom network routed winbind
cpqarrayd jexec nfs rstatd xfs
crond kadmin nfslock rusersd xinetd
cups kdcrotate nscd rwalld ypbind
dhcpd keytable ntpd rwhod yppasswdd
dhcrelay killall ospf6d saslauthd ypserv
firstboot kprop ospfd sendmail ypxfrd
functions krb524 pcmcia single zebra
[root@localhost init.d]# vi mysqld
#编写自己的服务,然后放在init.d目录下,再在对应的启动级别下加入超链接即可实现当机器启动时完成对相应服务的启动
附图
@Wentasy 博文仅供参考,欢迎大家来访。如有错误之处,希望批评指正。原创博文如需转载请注明出处,谢谢 :) [CSDN博客] |
第二部分 Linux Shell高级编程技巧——第三章 运行级别脚本介绍相关推荐
- 博客文件第二部分 Linux Shell高级编程技巧——第一章 深入讨论
最近研究博客文件,稍微总结一下,以后继续补充: 道歉 由于频视出了点问题,所以临时只有这点内容,期后再补上. 条记 #录记和域 #入深探讨awk #编辑 #vi awkif.sh #转变权限 [roo ...
- Linux/Unix系统编程手册 第三章:系统编程概念
本章介绍系统编程的基础概念和一些后续章节用到的函数及头文件,并说明了可移植性问题. 系统调用是受控的内核入口,通过系统调用,进程可以请求内核以自己的名义去执行某些动作,比如创建子进程,执行I/O操作, ...
- linux shell 高级编程,shell高级编程
条件选择if语句 选择执行: 注意:if语句可嵌套 单分支 if 判断条件;then 条件为真的分支代码 fi 双分支 if 判断条件; then 条件为真的分支代码 else条件为假的分支代码 fi ...
- Linux C高级编程——文件操作之库函数
Linux C高级编程--文件操作之库函数 宗旨:技术的学习是有限的,分享的精神是无限的 --为什么要设计标准I/O库? 直接使用API进行文件访问时,需要考虑许多细节问题 例如:read.write ...
- Linux C高级编程——文件操作之系统调用
Linux C高级编程文件操作之系统调用 宗旨:技术的学习是有限的,分享的精神是无限的! 库函数是一些完成特定功能的函数,一般由某个标准组织制作发布,并形成一定的标准.使用库函数编写的函数一般可以应用 ...
- Linux环境高级编程函数,Linux环境高级编程--出错处理(CLStatus)
很多程序库对外提供若干类,每个方法出错时如何告知调用者是否出错,以及出错码(在Linux上在error.h中的全局errno就是保存我们Linux程序执行的出错码的)?方法很多,为了简化起见,函数将返 ...
- linux环境编程 学习,学习linux环境高级编程首先学习的是文件的操作。因为有.pdf...
学习linux环境高级编程首先学习的是文件的操作.因为有 学习 Linux 环境高级编程,首先学习的是文件的操作.因为有一句很有趣的话"Linux 下一切皆文件".所以掌握了文件操 ...
- python高级应用_Python高级编程技巧
Python 高级编程技巧 本文展示一些高级的 Python 设计结构和它们的使用方法.在日常工作中,你可以根据需要 选择合适的数据结构, 例如对快速查找性的要求. 对数据一致性的要求或是对索引的要求 ...
- Linux 服务器高级编程ET LT代码
linux 服务器高级编程ET LT代码 #include<sys/types.h> #include<sys/socket.h> #include<netinet/in ...
最新文章
- 洛谷—— P1869 愚蠢的组合数
- 【python技巧】“”、“”等符号操作
- 后台开发经典书籍--代码大全
- 关于虚拟机第二块网卡eth1(仅主机模式)的配置问题
- python标准库os的方法listdir_使用python标准库快速修改文件名字
- asp连接mysql oledb_provider=microsoft.jet.oledb……数据库连接方法的疑惑?
- 11(AtCoder-2649)
- rspec 测试页面元素_如何使用RSpec对Go应用进行黑盒测试
- 如何运行python代码
- Spring Boot 2.0.0.M7 生产环境部署
- *第十周*数据结构实践项目一【二叉树的链式存储算法库】
- 练字第一方案失败,转向第二方案
- java游戏下载网址_手机java游戏下载网站
- 让选择更具明确性:土方计算方法的选择——方格网or三角网
- 计算机网络校园网建设设计摘要,计算机网络专业毕业论文校园网建设设计.doc...
- clover UEFI+GUID最简单显核安装黑苹果教程(易懂)
- 计算机的喇叭接口显示的英文,电脑上喇叭图标不见了怎么找到(电脑不显示扬声器图标的解决方法)...
- 三棱锥内切球半径求法
- Mock测试详细介绍及使用
- python代码雨教程-python实例代码
热门文章
- 屏蔽Backspace(退格)键后退功能
- QPS、TPS、RT、并发用户数、吞吐量
- 2019年第一本书《幸福的婚姻》思维导图+感想
- CycleGAN训练自己的数据集
- [幻灯更新]9月27日-9月28日剔除“伪创新”和“无领域”的领域驱动设计-网络公开课
- 创建非模态对话框时向非模态对话框传递参数方法
- Java中的escape,unescape方法
- 数据库——数据库的创建
- 数字信号处理_第1个编程实例
- Http_4个新的http状态码:428、429、431、511