bug宝典Linux篇 kill 命令

来源:互联网 发布:马天宇女装知乎 编辑:程序博客网 时间:2024/06/05 16:38

使用jenkins做参数化构建,执行下面的shell脚本

# echo 命令是在现实器上显示一段文字,下面就是把变量project_name打印出来echo $project_nameecho $tomcat_homeecho $link_tomcat# 显示今天,日期格式设置today=`date +%Y-%m-%d`# ps -ef 是显示所有进程,通过 grep筛选出您所需要的进程# ps -ef | grep ${link_tomcat} 则表示显示${link_tomcat}这个变量的进程,当然这个变量我是在jenkins中配置的。# grep -v grep命令是去掉grep命令自身# awk '{print $2}' 截取 $2 第二个域的pid号# kill -9 强杀进程# xargs 使用上一个操作的结果作为下一个命令的参数使用ps -ef | grep ${link_tomcat} | grep -v grep | awk '{print $2}'| xargs kill -9

1
提示错误信息如下:

[fontal] $ /bin/sh -xe /usr/local/application/tomcat8_1/temp/hudson1326966671395768233.sh+ echo fontalfontal+ echo /usr/local/application/apache-tomcat-8.0.30.1/usr/local/application/apache-tomcat-8.0.30.1+ echo tomcat8_2tomcat8_2++ date +%Y-%m-%d+ today=2016-12-04+ ps -ef+ awk '{print $2}'+ grep tomcat8_2+ xargs kill -9+ grep -v grepUsage: kill [options] <pid|name> [...]Options: -a, --all              do not restrict the name-to-pid conversion to processes                        with the same uid as the present process -s, --signal <sig>     send specified signal -q, --queue <sig>      use sigqueue(2) rather than kill(2) -p, --pid              print pids without signaling them -l, --list [=<signal>] list signal names, or convert one to a name -L, --table            list signal names and numbers -h, --help     display this help and exit -V, --version  output version information and exitFor more details see kill(1).Build step 'Execute shell' marked build as failureFinished: FAILURE

从命令上将,貌似没有问题。于是我猜想是不是tomcat8_2没有启动,执行这个命令就有问题。启动动试试,执行成功。
1
从下面的结果看是执行成功了,看来我要解决的问题是,如何解决这个命令执行异常,能让jenkins参数化构建继续下去。
2

0 0
原创粉丝点击