|
|
发表于 2006-9-29 18:41:39
|
显示全部楼层
‘模拟系统启动时屏幕输出文本’脚本:
研究 RH 日志文件,查找启动系统时的屏幕输出信息时,发觉启动信息不是十分完全。翻翻启动程式(如rc.sysinit),写写‘模拟屏幕输出文本’脚本:
root权限操作
# vi /root/bin/wlook-info.sh
---------------------------------------
#!/bin/bash
## scriptname: wlook-info.sh
# Root权限执行脚本
if [ $(id -gn) != "root" ] ;then
echo Permission denied
exit
fi
# 建立操作目录
[ -d /tmp/wbootdir ] || mkdir /tmp/wbootdir
# 准备载入模块信息
w_sd=0;w_scsi=0;w_jbd=0;w_sc=0
if lsmod|grep -q '^sd_mod';then w_sd=1;fi
if lsmod|grep -q '^scsi_mod';then w_scsi=1;fi
if lsmod|grep -q '^jbd';then w_jbd=1;fi
[[ $w_sd -eq 1 && $w_scsi -eq 1 ]] && w_sc=1
# grub 装载内核信息
sed '/^#/d' /etc/grub.conf | sed -n '/^title/,$p' | sed 's/^[[:space:]]//' > /tmp/wbootdir/gr.t
w_nu=$(grep -c '^title' /tmp/wbootdir/gr.t)
filename='/tmp/wbootdir/gr.t'
n=0
# 多项内核引导信息,title 不止一项时
if [ $w_nu -ne 1 ];then
while read LINE
do
case "${LINE}" in
title*)
((n=n+1))
echo "${LINE}" > /tmp/wbootdir/wgr.$n ;;
*) echo "${LINE}" >> /tmp/wbootdir/wgr.$n ;;
esac
done < /tmp/wbootdir/gr.t
# 提取内核信息,如果脚本不能判断内核信息
# 如内核经过编译,‘Change it you':自己编辑信息
if grep -ql "kernel.*$(uname -r)" /tmp/wbootdir/wgr* ;then
w_wgr=$(grep -l "kernel.*$(uname -r)" /tmp/wbootdir/wgr*)
filename=$(echo ${w_wgr}|awk '{print $1}')
else
echo 'title Change it you' > /tmp/wbootdir/w_gr.test
echo 'root (hd0,0)' >> /tmp/wbootdir/w_gr.test
echo 'kernel /boot/NEW ro root=/dev/NEW' >> /tmp/wbootdir/w_gr.test
echo 'kernel /boot/NEW-initrd-NEW.img' >> /tmp/wbootdir/w_gr.test
filename='/tmp/wbootdir/w_gr.test'
fi;fi
# 输出grub引导信息
clear
while read LINE
do
case "${LINE}" in
title*)
w_ti=$(echo "${LINE}"|awk -F'title' '{print $2}')
(echo "Booting '$w_ti '" ; echo) >> /tmp/wbootdir/bootlog
;;
root*)
echo "${LINE}" >> /tmp/wbootdir/bootlog
echo " Filesystem type is ext2fs, partition type 0x83" >> /tmp/wbootdir/bootlog
;;
kernel*)
echo "${LINE}" >> /tmp/wbootdir/bootlog
echo -e "\t[Linux-bzImage, setup=0x1400, size=0xfaxxx]">> /tmp/wbootdir/bootlog
;;
initrd*)
echo "${LINE}" >> /tmp/wbootdir/bootlog
echo -e "\t[Linux-initrd @ 0xbea8000, 0x37cd2 bytes]">> /tmp/wbootdir/bootlog
;;
*) echo "${LINE}" >> /tmp/wbootdir/bootlog;;
esac
done < $filename
cat /tmp/wbootdir/bootlog
# 解压内核的信息
echo -e "Uncompressing Linux .\c";sleep 0.5;echo -e ".\c";sleep 1
echo -e ". \c";sleep 0.5;echo -e " OK, booting the kernel.\n"
sleep 1
# 抽取/var/log/dmesg文件中信息,并补充模块信息
sed -n '1,/^[Aa]dding [Ss]wap:/p' /var/log/dmesg > /tmp/wbootdir/wdm.t
while read LINE
do
if echo "${LINE}"|grep -q '^[Jj]ournalled [Bb]lock [Dd]evice';then
[ $w_jbd -eq 1 ] && echo 'Loading jbd module'
fi
echo "${LINE}"
if echo "${LINE}"|grep -q '^Linux version';then sleep 1;fi
if echo "${LINE}"|grep -q '^.*ide1';then sleep 0.5;fi
if [ $w_sc -eq 1 ];then
if echo "${LINE}"|grep -q '^VFS: [Mm]ount';then
echo 'Red hat nash version 3.3.10 starting'
echo 'Loading scsi_mod module'
sleep 0.5 ;fi
if echo "${LINE}"|grep -q '^[Kk]mod: failed';then
echo 'Loading sd_mod module'
w_sc=0;fi
fi
done < /tmp/wbootdir/wdm.t
# init 程序标题信息
sleep 1
echo -e "INIT: \c";sleep 0.3;echo "version 2.84 booting"
sleep 1
# 输出欢迎信息
echo -en "\t\tWelcome to \e[1;31mRedHat \e[0mLinux\n"
echo -en $"\t\tPress 'I' to enter interactive startup.\n"
#
#
#
# /var/log/boot.log 中抽取rc.sysinit输出信息
boottime=$(sed -n '$p' /var/log/boot.log | sed 's/[0-9][0-9]:[0-9][0-9]:[0-9][0-9] .*//')
grep "^${boottime}" /var/log/boot.log > /tmp/wbootdir/bw.log
b_nu=$(grep -c "syslogd startup succeeded" /tmp/wbootdir/bw.log)
# 如果一日重启多次,抽取最后一次启动信息
if [ ${b_nu} -eq 1 ];then
cp -f /tmp/wbootdir/bw.log /tmp/wbootdir/bootw.log
else
n=1
while (( $n > 0 ))
do
if tail -n $n /tmp/wbootdir/bw.log|grep -q "syslogd startup succeeded";then
tail -n $n /tmp/wbootdir/bw.log > /tmp/wbootdir/bootw.log
n=0
else
(( n=n+1 ))
fi
done
fi
# 初始化‘启动服务’,最后一次启动信息作备份
if grep -q 'rc.sysinit:' /tmp/wbootdir/bootw.log ;then
cp -f /tmp/wbootdir/bootw.log /tmp/rb.wei
else
if [ -f /tmp/rb.wei ] ;then
cp -f /tmp/rb.wei /tmp/wbootdir/bootw.log
else
echo 'Tips : rc.sysinit: tips reboot ' > /tmp/wbootdir/bootw.log
fi;fi
if [ -f /tmp/b_t_w.log ] ;then
bootw='/tmp/b_t_w.log'
else
bootw='/tmp/wbootdir/bootw.log'
cp /tmp/wbootdir/bootw.log /tmp/b_t_w.log
fi
# 制作输出信息
grep 'rc.sysinit:' ${bootw} | awk -F'sysinit: ' '{print $2}' | sed 's/ succeeded//' > /tmp/wbootdir/bw1.log
grep -v 'rc.sysinit:' ${bootw} > /tmp/wbootdir/bw2.log
# ‘格式输出’变量
b_le=$(runlevel | awk '{print $2}')
b_ok="[ \e[1;32m OK \e[0m ]"
# 输出rc.sysinit程式信息
while read LINE
do
printf "%-59s%-6s\n" "${LINE}" "$(echo -e "$b_ok")"
if echo "${LINE}" | grep -q '[Cc]hecking root filesystem' ;then
sleep 1
if grep -q '/: clean' /tmp/wbootdir/bw2.log ;then
grep '/: clean' /tmp/wbootdir/bw2.log | cut -d':' -f4-
printf "%78s\n" "$(echo -e "$b_ok")"
fi;fi;done < /tmp/wbootdir/bw1.log
# 补充运行级别,非交互式启动
echo -e "\nINIT:Entering runlevel: ${b_le}\n"
echo 'Entering non-interactive startup'
# 初始化‘服务启动’信息后,读取信息
if [ -f /tmp/b_s_w.log ];then
while read LINE
do
echo "${LINE}"
echo "${LINE}" | grep -q 'Checking for new hardware' && sleep 5
echo "${LINE}" | grep -q 'xinetd:' && sleep 2
done < /tmp/b_s_w.log
rm -f /tmp/b_t_w.log
else
# 初始化‘服务启动’信息
# 提示在控制台(黑屏)初始化
b_tty=$( ps | grep ps | awk '{print $2}')
if [[ ${b_tty} != tty[0-9] ]] ;then
echo -e "\n== > Runs Scripts on console ! \n"
exit
fi
# 初始化,并存入‘读取信息’文本
for b_file in $(ls /etc/rc.d/rc${b_le}.d/S*)
do
${b_file} stop > /dev/null
${b_file} start
done | tee /tmp/b_s_w.log
echo '' >> /tmp/b_s_w.log
fi
# 清屏
sleep 1;clear
# 输出系统信息
cat /etc/redhat-release
echo "Kernel $(uname -r) on an $(uname -m)"
# 模拟登录
echo -e "\n\n\nlocalhost login: _\npasswd: \n\n"
echo
# 删除操作目录
rm -rf /tmp/wbootdir
# 清空变量
set --
---------------------------------------
# chmod +x /root/bin/wlook-info.sh
第一次运行脚本,要求在控制台(黑屏)执行
# wlook-info.sh
实例 1
屏幕输出文本到文件
# wlook-info.sh | tee /tmp/filename
实例 2
硬件变动,‘服务启动’修改。需要重新初始化获取准确信息
删除‘读取信息’文本
# rm /tmp/b_s_w.log
重新初始化
# wlook-info.sh
实例 3
除了第一次初始化外,在X(图形界面)或控制台没有分别
--------------------
注:如果粘贴脚本麻烦,下载附件中的脚本。
---
--- |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|