linux通过grep kill掉tomcat进程脚本,百分百kill掉

来源:互联网 发布:怎么用java写服务器 编辑:程序博客网 时间:2024/06/18 12:13
#!/bin/shsource /etc/profilepid=`ps -ef | grep "testtomcat" | grep -v 'grep\|tail\|less\|more'| awk '{print $2}'` if [ "$pid" != "" ] ; then        kill -9 $pid        rm -f /opt/testtomcat/pidelse     rm -f /opt/testtomcat/pidfirm -rf   /opt/testtomcat/webapps/testtomcatsh /opt/testtomcat/bin/startup.sh

1、 解释一下 grep -v ‘grep|tail|less|more’,一般会有查看日志的进程,这个排除掉grep,tail,less,more的进程,不会杀死这些进程

2、了解#!/bin/sh

!/bin/bash是指此脚本使用/bin/bash来解释执行。其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径, bash只是shell的一种,还有很多其它shell,如:sh,csh,ksh,tcsh,…
Linux 中的 shell 有很多类型,其中最常用的几种是: Bourne shell (sh)、C shell (csh) 和 Korn shell (ksh), 各有优缺点,Bourne shell 是 UNIX 最初使用的 shell,并且在每种 UNIX 上都可以使用, 在 shell 编程方面相当优秀,但在处理与用户的交互方面做得不如其他几种shell;Linux 操作系统缺省的 shell 是Bourne Again shell,它是 Bourne shell 的扩展,简称 Bash,与 Bourne shell 完全向后兼容,并且在Bourne shell 的基础上增加、增强了很多特性;Bash放在/bin/bash中,它有许多特色,可以提供如命令补全、命令编辑和命令历史表等功能,它还包含了很多 C shell 和 Korn shell 中的优点,有灵活和强大的编程接口,同时又有很友好的用户界面。

0 0
原创粉丝点击