LinuxSir.cn,穿越时空的Linuxsir!

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

请问bash脚本里如何判断一个模块是否装卸成功?

[复制链接]
发表于 2006-3-31 10:45:46 | 显示全部楼层 |阅读模式
我需要在bash脚本里实现类似下面的功能

if  insmod **.o成功(或者 rmmod **成功)
     then   dosomething

     else   dootherthing
fi


请问应该怎么实现,谢谢
发表于 2006-3-31 10:58:22 | 显示全部楼层
就是这样了,一点没错。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-31 11:36:31 | 显示全部楼层
噢,原来就这么简单。

那是不是每个命令都可以这样做呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-31 11:38:14 | 显示全部楼层
存在一个问题:insmod失败有可能是因为之前已经加载过造成的,怎么区别这种特殊的情况呢?
回复 支持 反对

使用道具 举报

发表于 2006-3-31 11:38:33 | 显示全部楼层
是,if语句是根据命令的返回值来判断是否运行接下来的命令的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-31 12:28:15 | 显示全部楼层
请问哪里有命令的返回值或者出错信息代码的资料?
回复 支持 反对

使用道具 举报

发表于 2006-3-31 12:33:36 | 显示全部楼层
看 man 。 0 一般都是表示成功,非 0 返回值意义各不同。
回复 支持 反对

使用道具 举报

发表于 2006-3-31 12:37:17 | 显示全部楼层
  1. EXIT STATUS
  2.        For the shell’s purposes, a command which exits with a zero exit status  has  succeeded.   An  exit status of zero indicates success.  A non-zero exit status indicates failure.  When a command terminates on a fatal signal N, bash uses the value of 128+N as the exit status. If  a command is not found, the child process created to execute it returns a status of 127.  If a command is found but is not executable,  the  return  status  is 126. If  a  command fails because of an error during expansion or redirection, the exit status is greater than zero.

  3.        Shell builtin commands return a status of 0 (true)  if  successful,  and  non-zero (false) if an error occurs while they execute.  All builtins return an exit status of 2 to indicate incorrect usage. Bash itself returns the exit status of the last command executed, unless a  syntax error  occurs,  in  which  case it exits with a non-zero value.  See also the exit builtin command below.
复制代码


摘录自bash的man。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-31 13:18:03 | 显示全部楼层
我是想知道insmod和rmmod的返回值,但是他们的man里没有。


就是实现以下功能

if (insmod **.o)
     then dosomething

elif(insmod因为模块已加载而失败)
    then dosomething

elif(insmod因为其他原因失败)
   then dootherthing
fi

我需要区分失败的原因。
回复 支持 反对

使用道具 举报

发表于 2006-3-31 13:48:40 | 显示全部楼层
insmod的返回值似乎只有1和0。
回复 支持 反对

使用道具 举报

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

本版积分规则

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