LinuxSir.cn,穿越时空的Linuxsir!

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

shell脚本里dhcpcd命令不执行

[复制链接]
发表于 2004-4-27 15:53:01 | 显示全部楼层 |阅读模式
root权限在bash下执行下面两条命令:
#kill -1 `cat /var/run/dhcpcd-eth0.pid`
杀死dhcpcd进程,正确
#/sbin/dhcpcd -H -D -R -N -t 999999 eth0
重庆启动dhcpcd程序,正确

当把这两句语句放入shell脚本后就不正确了,
脚本退出后dhcpcd进程已没有,说明第一条语句正确执行,第二条语句没有执行成功。
返回的信息是:
******/sbin/dhcpcd: already runing
******/sbin/dhcpcd: if not then delete /var/run//dhcpcd-eth0.pid file

可shell退出后查分明没有/var/run/dhcpcd-eth0.pid文件了,

这是什么原因,我需要在shell中用kill和dhcpcd停启dhcpcd进程。
发表于 2004-4-27 16:24:42 | 显示全部楼层
用kill -9,因为-1并没有真正杀死进程
 楼主| 发表于 2004-4-28 12:46:40 | 显示全部楼层

ok,解决。

试过了kill -9也不行,kill -1也把进程杀掉了的。

不过我找到ifup-dhcp的脚本片断,已经解决。把for循环加在1,2语句之间就可了,这个for循环应该是延时的功能,
continue是什么??
没有用过continue函数,
,我猜应该是用来跳出for循环吧。1表示跳出一级。

#1
kill -1 `cat /var/run/dhcpcd-eth0.pid`

for ((wait=0; wait<30; wait++)); do
  if test -d /proc/$i; then usleep 300000
  else continue 1
  fi
  if [ $wait = 20 ]; then
    echo process $i still not dead,sending SIGKILL
    kill -KILL $i &>/dev/null
  fi
done

#2
/sbin/dhcpcd -H -D -R -N -t 999999 eth0
 楼主| 发表于 2004-4-28 13:03:01 | 显示全部楼层

奇怪么?

发现一个奇怪的现象
如果脚本利用这条语句
kill -1 `cat /var/run/dhcpcd-eth0.pid`

for循环中的
if [ $wait = 20 ]; then
echo process $i still not dead,sending SIGKILL
kill -KILL $i &>/dev/null
就执行了,


如果脚本中
kill -1语句换成
pid=`cat /var/run/dhcpcd-eth0.pid`
kill -1 $pid

那么for循环里的
if [ $wait = 20 ]; then
echo process $i still not dead,sending SIGKILL
kill -KILL $i &>/dev/null
就不会被执行,

从现象上看好像是第一种kill比第二中kill花的时间长。
发表于 2004-4-28 13:08:18 | 显示全部楼层
你的脚本有误。
$i还是$wait呢?最好不要引用那些关键词如wait等。
 楼主| 发表于 2004-4-28 13:31:02 | 显示全部楼层
就是wait, $wait
for片断是从suse的ifup-dhcp上cut下来的。
发表于 2004-4-28 13:39:00 | 显示全部楼层
不明白你要干什么?!
用-x选项调试一下你的脚本,看问题出在何处!
bash -x urscript
 楼主| 发表于 2004-4-28 13:47:06 | 显示全部楼层
还不明白呀
用kill杀dhcpcd,然后用/sbin/dhcpcd重新启动网卡
发表于 2004-4-28 13:53:12 | 显示全部楼层
1,用ps找出你要杀的进程ID,
2,kill -9 这个ID,
3,重新启动那个进程,
怎么看着那么复杂呀~~~
发表于 2004-4-28 14:12:09 | 显示全部楼层
不是断章取义吧。

  1. for (([color=red]wait[/color]=0; wait<30; wait++)); do
  2. if test -d /proc/[color=red]$i[/color]; then usleep 300000 [color=red]# $i ???[/color]
  3. else continue 1
  4. fi
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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