LINUX自动运行程序怎么设置
学习啦在线学习网LINUX自动运行程序怎么设置
学习啦在线学习网 这里学习啦小编介绍Linux中的cron命令和at命令,来设置LINUX自动运行程序。但是一些命令知识并不清楚,所以学习啦小编来帮助大家提升LINUX操作系统的命令知识,欢迎大家来阅读!!!
LINUX自动运行程序怎么设置
crontab文件的存放路径是/etc/crontab
cron用来执行周期性的事件,cron命令有个一个特殊的文件与之对应,内容如下
[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文件进行配置,下面是inittab文件的内容
# 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:】就是说本系统默认是以X11也就是x-window的模式启动。
学习啦在线学习网 Runlevel 0 ——init关闭所有进程并终止系统。
Runlevel 1 ——转到单用户模式
Runlevel 2 ——进入多用户的模式
Runlevel 3 ——多用户模式,也是多数服务器的默认模式。
Runlevel 4 —— 一般不使用,可以实现一些特定的登录请求。
Runlevel 5 ——X Window终端。
Runlevel 6 ——是关闭进程并重新启动系统。
/etc/rc开头的文件,一般都是系统启动后自动执行的文件。rc开头的文件很多,如下:
rc rc1.d/ rc3.d/ rc5.d/ rc.d/ rc.sysinit
学习啦在线学习网 rc0.d/ rc2.d/ rc4.d/ rc6.d/ rc.local
学习啦在线学习网 其中init是所有进程之父 init读取/etc/inittab,执行rc.sysinit脚本
学习啦在线学习网 运行顺序由inittab中设置的init tree决定,一般设置为: /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默认是用户自定义的脚本
学习啦在线学习网 /etc/rc.d/rc.local文件内容如下:
学习啦在线学习网 [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
经常使用的 rc.local 则完全是习惯问题,不是标准。不过使用 rc.local是个好习惯。