|
发表于 2004-4-12 17:15:46
|
显示全部楼层
最初由 home_king 发表
to devel:
脚本粗糙冗长了点,而且存在bugs,比如权限问题(只有root才能写inittab)。:p
况且,无需写脚本,在grub界面按下e,把kernel选项行添上n(3-5)即可。因为默认运行级别没必要经常改动,一般安装NV驱动时用到而已。
:rolleyes: 谢谢!!我一直没有注意。。任何脚本都需要检查这一步的。我改了改,看还有需要修改的地方吗?
- #!/bin/bash
- # change the run level at the boot time.
- if [ `echo $USER` != root ] ; then #检查当前用户是否是root.
- echo "Current user is not root" ; exit 0
- fi
- tempfile="1"
- while [ -e $tempfile ] ; do # 检查临时文件是否存在。
- tempfile=$(($tempfile+1))
- done
- grep id /etc/inittab
- echo "Are you want change the runlevel at the boot ? (y/n) "
- read num
- if [ $num == "y" ] ; then
- if [ -e /etc/inittab ] ; then
- echo 'Input a number for runlevel at system boot:'
- read level
- if [[ $level = ^[0-6] || ${#level} > 1 ]] ; then #检查输入是否是 0到6的数字
- echo "The number is wrong."
- else
- sed 's/id:[12345]:in/id:'$level':in/' /etc/inittab >$tempfile&&cat $empfile>/etc/inittab
- rm -f $tempfile&&chmod 644 /etc/inittab
- fi
- else echo "File not found!"
- fi
- else echo "The run level have not change!"
- fi
- grep id /etc/inittab
复制代码 |
|