linux系统启动之后运行的最后的脚本,linux 启动顺序及启动时自动运行脚本

在Redhat Redflag centos fc linux系统里面脚本的启动先后顺序:

第一步:通过/boot/vm进行启动 vmlinuz

第二步:init /etc/inittab

第三步:启动相应的脚本,并且打开终端

rc.sysinit

rc.d(里面的脚本)

rc.local

第四步:启动login登录界面 login

第五步:在用户登录的时候执行sh脚本的顺序:每次登录的时候都会完全执行的

/etc/profile.d/file

/etc/profile

/etc/bashrc

/root/.bashrc

/root/.bash_profile

Redhat中的运行模式2、3、5都把/etc/rc.d/rc.local做为初始化脚本中的最后一个,所以用户可以自己在这个文件中添加一些需要在其他初始化工作之后,登录之前执行的命令。

也可将自己写好的脚本或命令写入/etc/rc.local文件中。系统会根据该文件来启动所指定的脚本或命令。

下面为httpd服务做了一个启动脚本。

功能:在Linux系统启动时检查httpd服务是否启动成功,如果服务已启动,将日志写入log。如果没有启动,则立即启动httpd服务,并将日志写入log。

[web@info data]$ vi/data/http.sh#/bin/bash

log_file=/data/http_state.log

echo "" >$log_file;

http_status=`netstat -nat|grep 80|awk {print $4}`

port=`echo ${http_status:3:3}`;

#echo $port;

if [ "${port}" == "80" ]; then

echo "http server already start!" >>$log_file;

elif [ "${port}" == "" ]; then

echo "http server stop!" >>$log_file;

/usr/sbin/httpd  -k stop 2>&/dev/null;

fi

将写好的脚本加入/etc/rc.local中

[web@info data]$ echo "/data/http.sh" >>/etc/rc.local ;tail -1 /etc/rc.local/data/http.sh

[web@info data]$ cat /data/http_status.log

http server stop!

[web@info data]$ netstat -nat|grep 80

tcp        0      0 :::80                       :::*                        LISTEN

--======================================================

[grid@PC62 rc.d]$ pwd

/etc/rc.d

[grid@PC62 rc.d]$ more chdisk.shchown grid:dba /dev/sdb

chown grid:dba /dev/sdc

chown grid:dba /dev/sdd

chmod 660 /dev/sdb

chmod 660 /dev/sdc

chmod 660 /dev/sdd

[grid@PC62 rc.d]$ more 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

/etc/rc.d/chdisk.sh

[grid@PC62 rc.d]$

vi /etc/inittab

修改启动的级别

修改启动服务

ntsysv

network

sshd

rawdevices

sysstat

xfs

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值