我是靠谱客的博主 柔弱小天鹅,这篇文章主要介绍bug宝典Linux篇 kill 命令,现在分享给大家,希望可以做个参考。

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

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
# echo 命令是在现实器上显示一段文字,下面就是把变量project_name打印出来 echo $project_name echo $tomcat_home echo $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
提示错误信息如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[fontal] $ /bin/sh -xe /usr/local/application/tomcat8_1/temp/hudson1326966671395768233.sh + echo fontal fontal + echo /usr/local/application/apache-tomcat-8.0.30.1 /usr/local/application/apache-tomcat-8.0.30.1 + echo tomcat8_2 tomcat8_2 ++ date +%Y-%m-%d + today=2016-12-04 + ps -ef + awk '{print $2}' + grep tomcat8_2 + xargs kill -9 + grep -v grep Usage: 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 exit For more details see kill(1). Build step 'Execute shell' marked build as failure Finished: FAILURE

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

最后

以上就是柔弱小天鹅最近收集整理的关于bug宝典Linux篇 kill 命令的全部内容,更多相关bug宝典Linux篇内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部