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是个好习惯。