LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 949|回复: 13

请教如何在.sh里改变某个程序的runlevel?[基本解决]

[复制链接]
发表于 2004-4-11 19:08:03 | 显示全部楼层 |阅读模式
我在装显卡驱动,它要在level 3下运行,我想做一个.sh,自动安装显卡驱动,而在.sh 里用 init 3时,是会到level 3,但是.sh的脚本也到此止住,不会往下运行了,有没有办法在level 5里,暂时退到level 3,运行一些脚本/命令(如GraphicDriver.run),然后自动回到level 5啊?
发表于 2004-4-11 19:18:44 | 显示全部楼层
呵呵,这个无需用到脚本吧。
直接init 3进入runlevel 3安装驱动就是啦。
发表于 2004-4-11 19:28:46 | 显示全部楼层
telinit 3
发表于 2004-4-11 19:32:24 | 显示全部楼层

  1. #!/bin/bash
  2. # change the run level at the boot time.
  3. #time :2003.8.5
  4. grep id /etc/inittab
  5. echo "Are you want change the runlevel at the boot ? (y/n) "
  6. read num
  7. if [ $num = "y" ];then
  8.        if [ -e /etc/inittab ]
  9.              then echo "Input a number for runlevel at system boot:"
  10.                   read level
  11.                   if [[ $level = ^[0-9] || ${#level} > 1 ]]
  12.                             then echo "The number is wrong."
  13.                   else
  14.                          if [[ $level >0 && $level <6 ]]
  15.                                      then cat /etc/inittab|sed 's/id:[12345]:in/id:'$level':in/'>h&&cat h>/etc/inittab
  16.                                           rm -fr h&&chmod 644 /etc/inittab
  17.                          else echo "The number is wrong!"
  18.                          fi
  19.                   fi
  20.       else echo "File not found!"
  21.       fi
  22. else echo "The run level have not change!"
  23. fi
  24. grep id /etc/inittab
复制代码

基本能用!!

:rolleyes:
发表于 2004-4-11 19:33:59 | 显示全部楼层
最初由 zonzi 发表
telinit 3

telinit指向init的软链接,权限不同而已。

  1. [root@home root]# file /sbin/telinit
  2. /sbin/telinit: symbolic link to `init'
  3. [root@home root]# ls -l /sbin/telinit
  4. lrwxrwxrwx    1 root     root            4  2月 29 18:53 /sbin/telinit -> init
  5. [root@home root]# ls -l /sbin/init
  6. -rwxr-xr-x    1 root     root        28468  9月 23  2003 /sbin/init
复制代码
发表于 2004-4-11 19:38:48 | 显示全部楼层
to devel:
脚本粗糙冗长了点,而且存在bugs,比如权限问题(只有root才能写inittab)。:p
况且,无需写脚本,在grub界面按下e,把kernel选项行添上n(3-5)即可。因为默认运行级别没必要经常改动,一般安装NV驱动时用到而已。
发表于 2004-4-11 20:57:51 | 显示全部楼层
在运行级别3的终端执行命令,而不退出级别5!像这样:
(exec top -n 3 >/dev/tty1)
这样,直到tty1的top命令完成后才返回X下控制!
 楼主| 发表于 2004-4-11 23:33:43 | 显示全部楼层
好像推出init 3 后就不能执行拉阿
######################
runlevel3.sh:
echo "under Runlevel 3"
######################

##########################
runlevel5.sh:
echo "Before enter Runlevel 3"
exec ./runlevel3.sh -n 3
echo "Return to Runlevel 5"
##########################

当我运行./runlevel5.sh时,只显示了
Before enter Runlevel 3
under Runlevel 3
而没有
Return to Runlevel 5

怎么回事,错在哪里?
发表于 2004-4-11 23:52:15 | 显示全部楼层
晕~~呵呵,这里的-n 3是top命令的参数,不要理解为运行级别3哦。
还是手动来做吧,也不烦。
1. init 3
2. 安装驱动, 然后调整/etc/X11/XF86Config文件(如屏蔽# Load "dri")
3. init 5
无需3分钟搞定。
 楼主| 发表于 2004-4-12 09:52:26 | 显示全部楼层
唉,看来真的是没办法了嘛
我每次重装linux的时候都要做一些必做之事,所以想做一个.sh,一步到位啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表