Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  shell  >  正文 生产环境中用到的二个shell脚本

生产环境中用到的二个shell脚本

发布时间:2014-12-02   编辑:www.jquerycn.cn
分享二个在生产环境中用到的shell脚本,一个检测ssh攻击并报警,一个监测进程并重启。有需要的朋友参考下吧。

两个shell脚本:
1、检测SSH攻击,并报警。
 

复制代码 代码示例:
#!/bin/bash
#edit: www.jquerycn.cn
#Prevent SSH attack
#
SLEEPTIME=30
lastb -n 500| grep -v "^$" | grep -v "btmp" | awk '{print $3}' | sort | uniq -c  | grep -v "公司IP" |sort -nr > attack.log
while true
do
     while read line
     do
          IP=`echo $line | awk '{print $2}'`
          TIME=`echo $line | awk '{print $1}'`
          if [ "$TIME" -gt 10 ]; then
               grep "$IP"  /etc/hosts.deny &> /dev/null
               if [ "$?" -ne "0" ]; then
                   echo "sshd: $IP" >> /etc/hosts.deny
               fi
          fi
     done < attack.log
     /bin/sleep $SLEEPTIME
done

2、对线上服务进行监控,如果死掉,就立即重启,以httpd进程为例:
 

复制代码 代码示例:
#/bin/bash
# edit: www.jquerycn.cn
#
SLEEPTIME=30
while true
do
     id=`ps aux | grep httpd | grep -v "grep" | wc -l`
     if [ $id -lt 1 ]; then
         echo "---`date +"%F %H:%M:%S"`-----httpd restart." >> /u/scripts/httpd_monitor.log
         /etc/init.d/httpd start
     fi
     sleep $SLEEPTIME
done

您可能感兴趣的文章:
bash shell脚本执行的几种方法
inux shell初级入门教程
python shell是什么
深入解析tcsh的初始化配置文件
生产环境中用到的二个shell脚本
Shell 教程
shell中的random变量
Linux Source命令解析
解析shell字段分隔符的用法(图文)
获取不同linux系统类型的shell脚本(图文)

[关闭]