Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2917673
  • 博文数量: 454
  • 博客积分: 4860
  • 博客等级: 上校
  • 技术积分: 6375
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 10:08
个人简介

10年工作经验,专研网站运维。

文章分类

全部博文(454)

文章存档

2017年(11)

2016年(13)

2015年(47)

2014年(36)

2013年(147)

2012年(64)

2011年(136)

分类: 系统运维

2013-04-20 11:21:07

[root@localhost shelll-script]# cat stophttp.sh 
#!/bin/bash
#定义变量
PSline=12
psline=12
firsttime=1
lasttime=5
#停止服务
/etc/init.d/httpd stop
sleep 1
#每隔2秒查看服务是否停止
while [ $PSline -ge 2 ]
do
echo "It's stopping"
sleep 1s
PSline=`ps -ef | grep httpd | wc -l | awk '{print $1}'`
#判断服务是否停止,如果没停止,循环10次就杀死进程
if [ $firsttime -lt $lasttime ];then
echo "Wait a moment"
else
break;
fi
let "firsttime++"
done
ps -ef | grep httpd | awk '{print $2}'> /tmp/httppid.txt
for httppid in `cat /tmp/httppid.txt`;
do
kill -9 $httppid
done
#循环结束,显示成功信息
echo "It's stopped successful"
阅读(2154) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~