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

#!/bin/sh
source /etc/profile
pid=`ps -ef | grep "testtomcat" | grep -v 'grep\|tail\|less\|more'| awk '{print $2}'` 
if [ "$pid" != "" ] ; then
        kill -9 $pid
        rm -f /opt/testtomcat/pid
else 
    rm -f /opt/testtomcat/pid
fi
rm -rf   /opt/testtomcat/webapps/testtomcat
sh /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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值