想让命令开机自动运行,要怎么做?

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

想让命令开机自动运行,要怎么做?

#1

帖子 linunix » 2008-05-23 10:56

我是要运行
/usr/local/gw6c/bin/gw6c
于是把这一行加入了/etc/init.d/rc.local的最后一行,但是无效。

如果手动运行的话,必须得
cd /usr/local/gw6c/bin/gw6c
然后再
sudo ./gw6c
直接运行
sudo /usr/local/gw6c/bin/gw6c的话
就会出现配置文件读取错误。

于是我写了一个shell(自己瞎琢磨的)
内容如下
#!/bin/sh
cd /usr/local/gw6c/bin
./gw6c
cd ~
保存为文件名的gw6c的文件,放在/etc/init.d/目录下。
然后再在/etc/init.d/rc.loca的最后一行加上
/etc/init.d/gw6c

这样似乎就可以了,但是感觉不太好,似乎关机的时候偶尔会提示错误啥的。
请问那个Shell文件要怎么写?
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#2

帖子 solcomo » 2008-05-23 11:12

写到rc.local里啊
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
yiding_he
帖子: 2677
注册时间: 2006-10-25 18:10
来自: 长沙
联系:

#3

帖子 yiding_he » 2008-05-23 11:23

你是自由的。别人也是。
头像
yaoms
帖子: 4952
注册时间: 2007-10-19 14:51
来自: 深圳

#4

帖子 yaoms » 2008-05-23 11:24

$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /usr/local/gw6c/bin
./gw6c
exit 0
这是我的,没有出错。
Nothing 有事请发邮件到 yms541 AT gmail.com
alias 爱慕颇雷尔='mplayer'
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

#5

帖子 linunix » 2008-05-23 11:28

solcomo 写了:写到rc.local里啊
写到哪个rc.local?
/etc/init.d/rc.local
还是/etc/rc.local?

我写到/etc/init.d/rc.local也不行。
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

#6

帖子 linunix » 2008-05-23 11:29

yiding_he 写了:登录GNOME时自动运行程序
http://wiki.ubuntu.org.cn/%E7%99%BB%E5% ... B%E5%BA%8F
这个试过了,不行啊,加了sudo 或gksudo也不行。
头像
xiehuoli
帖子: 5941
注册时间: 2006-06-10 8:43
来自: 中国 CS

#7

帖子 xiehuoli » 2008-05-23 11:30

LS的4樓不是告訴你了嗎?
自己不看?
上次由 xiehuoli 在 2008-05-23 11:31,总共编辑 1 次。
年轻没有失败! ! ! ! ! !
噢!有怪兽,有怪兽!
头像
yaoms
帖子: 4952
注册时间: 2007-10-19 14:51
来自: 深圳

#8

帖子 yaoms » 2008-05-23 11:30

没看到我的回帖?
Nothing 有事请发邮件到 yms541 AT gmail.com
alias 爱慕颇雷尔='mplayer'
头像
solcomo
帖子: 2838
注册时间: 2007-04-25 13:12

#9

帖子 solcomo » 2008-05-23 11:31

就是4楼那样啊
♜♞♝♛♚♝♞♜
♟♟♟♟♟♟♟♟
♙♙♙♙♙♙♙♙
♖♘♗♕♔♗♘♖

☠☯⚔⚓☣☦☃☕
☹☻☪☭☬⚖⚛⚜
ℜℳℬ™ ℋℯℓ℘ ℳℭ
sƂɐʍ рǀɹoʍ əɥʇ oS
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

#10

帖子 linunix » 2008-05-23 11:40

yaoms 写了:
$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /usr/local/gw6c/bin
./gw6c
exit 0
这是我的,没有出错。
可以了,谢了。
原来是要添加在/etc/rc.local后面
而不是添加在/etc/init.d/rc.local后面
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

#11

帖子 linunix » 2008-05-23 11:43

顺便问一个,昨晚我添加了
http://ubuntu.cn99.com/ubuntu-cn/
的源后(用的是软件源的deb命令,而不是修改source.lst文件)

更新了一下,发现关机时不再出现那个进度条画面了,而出了一大串字符界面,似乎是关于network-manager什么的错误。

这是怎么回事?
头像
linunix
帖子: 424
注册时间: 2006-11-21 21:25

#12

帖子 linunix » 2008-05-23 11:50

yaoms 写了:没看到我的回帖?
对不起啊,没想到大家这么热情,我刚才是因为在重启试你这个办法,所以迟回复了,不通用的办法我就先回复了。
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#13

帖子 bones7456 » 2008-05-23 13:14

其实我那帖里面就已经有方法了啊。

posting.php?mode=quote&p=757998
关注我的blog: ε==3
回复