LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: atery

请问怎样开机自动运行一个要root权限的执行文件?

[复制链接]
 楼主| 发表于 2006-7-1 06:27:19 | 显示全部楼层
Post by 兰色风叶
直接编辑
/etc/rc.d/rc.local
也可以哦

I tried to add to my rc.local file as:
#!/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
./tpfan
./usr/local/bin/tpb

The last two lines are what I added. But nothing happens... sorry for the english (scim still got problem...)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-1 06:31:50 | 显示全部楼层
Post by seamonkey
你不妨把文件贴出来看看,加入/etc/init.d/后还要在相应的运行级目录/etc/rcN.d中做链接。

Post by fsm11
你可以在init.d里面建立一个文件:
如 #vi test.sh
    #./path/filename
保存
让后在RCN.D里面作一个链接估计就可以启动了


I´ll try this, just one thing: there are rc0.d, rc1.d ... rc6.d folders, anyone is OK?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-1 07:12:02 | 显示全部楼层
I´ve tried to copy my script in the init.d folder and link to rc6.d.It works. But there is one problem which is very annoying. The script runs to read the temperatures of the CPU etc. and control the fan every 3 seconds, so the file will continue for every in the terminal. As a result when the system is still initializing, the terminal will work there FOREVER and can´t log in...

I tried to creat a new shell script as
./tpfan -d
to let it run as a daemon. Also I changed the link file. But nothing changes, it´s the same... but if I run the command ./tpfan -d in terminal after I logged in GNOME, the script will work as a daemon. Very strange, any suggestions? thanks
回复 支持 反对

使用道具 举报

发表于 2006-7-1 08:05:45 | 显示全部楼层
Post by atery
I´ll try this, just one thing: there are rc0.d, rc1.d ... rc6.d folders, anyone is OK?
Not really!  These directories store the symlinks for the run control daemons for the corresponding runlevel.  Usually, you may add your symlink(s) to runlevel 3 or 5, in a multi-user environment depends on whether you are using GUI.

Have a look at this to learn about the meanings of runlevel
http://www.iodynamics.com/education/runlevel.html

Within these directories, you may see SxxSomeCommands and KxxSomeCommands.  xx is the sequence no., the bigger the no., the later the process will  be started (Sxx...) or killed (Kxx...).

Adding your symlink to rc6.d is definitely inappropriate.  rc6.d stores the symlinks for rebooting your computer, it should only kill processes rather than start a new process!
回复 支持 反对

使用道具 举报

发表于 2006-7-1 13:57:58 | 显示全部楼层
你把他加到rc3.d和rc5.d就可以了吗
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-7-1 16:07:36 | 显示全部楼层
谢谢各位的耐心,我昨天晚上试了一下,很奇怪。。。:

最开始我在local.rc里面加了两行(两个程序需要权限运行):
#!/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
./tpfan
/usr/local/bin/tpb

最后两行是我加的,结果发现没有任何反应。然后我错误的把tpfan(一个shell script)拷贝到rc6.d(链接)目录里面了。再次重启tpfan居然自己运行了,可是这个script如果不加-d参数让它后台运行的话就会在terminal里面一直运行不断列出当前的cpu等的温度,结果我启动的时候就卡在那里的,只好Ctrl+C。后来自己进去ini.d和rc6.d目录把刚才拷贝的脚本和链接都删了,结果开机还是自动运行着,感觉就是rc.local开始起作用了,试着修改rc.local的倒数第二行./tpfan -d,结果再次开机这个程序就后台运行了。很奇怪,最开始不行,当我拷贝进入init.d和rc6.d目录后在删除,就可以了。

第二个程序不是脚本,是直接执行的程序(我还没太弄明白。。。),我理解就象windows的exe文件。关键是开机它还是不运行,我象第一个程序那样操作了一遍也是不行。而且讨厌的是这个程序运行也要输入tpb -d才好后台运行。。。我试着自己作了个shell script:
#!/bin/sh
/usr/local/tpb -d

然后把它放到init.d目录里面,然后链接放在rc3.d里面,启动还是没有运行,不知道怎么回事
回复 支持 反对

使用道具 举报

发表于 2006-7-1 17:27:03 | 显示全部楼层
兄弟应该先去了解不同 run level 的作用
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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