加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

SHELL训练营--day13_shell练习

发布时间:2020-12-15 23:04:23 所属栏目:安全 来源:网络整理
导读:#输入数字,运行对应命令。 #!/bin/bash while: do read -p "please input a number: "n if [ -z "$n" ] then echo "请输入一个纯数字,1~4" sleep 3 continue n1=`echo $n|sed ‘s/[0-9]//g‘` if [ -n $n1 ] then echo "请输入一个纯数字,1~4" sleep 3 el
#输入数字,运行对应命令。 #!/bin/bash while: do read -p "please input a number: "n if [ -z "$n" ] then echo "请输入一个纯数字,1~4" sleep 3 continue n1=`echo $n|sed ‘s/[0-9]//g‘` if [ -n $n1 ] then echo "请输入一个纯数字,1~4" sleep 3 else break done case $n in 1) date ;; 2) ls ;; *) echo "请输入一个纯数字,1~4" ;; esac #批量创建用户 #!/bin/bash for i in `seq -w 00 09` do useradd user_$i p=`mkpasswd -l 10 -s 0` echo "user_$i $p" >> /tmp/pass.tmp/pass echo "$p"|passwd --stdin user_$i done #监控httpd进程 #!/bin/bash check_service() { c=0 for i in `seq 1 5` do /usr/local/apache2/bin/apachectl -k restart 2> /tmp/httpd.err if [ ! $? -eq 0 ] then c=$[$c+1] else break fi done if [ $c -eq 5 ] then python mail [email?protected] "apache重启失败" "`head -1 /tmp/httpd.err`" exit } while: do n=`ps -C httpd --no-heading|wc -l` if [ $n -ge 500 ] then check_service sleep 60 n_new=`ps -C httpd --no-heading|wc -l` if [ $n_new -ge 500 ] then python mail [email?protected] "apache重启失败" "请检查服务器" exit fi fi sleep 10 done # 根据日志封IP #!/bin/bash block_ip() { t1=`date -d "-1 min" +%Y:%H:%M` log=/data/logs/access_log egrep "$t1:[0-9+]" $log > /tmp/tmp_last_min.log awk ‘{print $1}‘ /tmp/tmp_last_min.log |sort -n |uniq -c |sort -n |awk `$1>100 {print $2}` >/tmp/bad_ip.list n=`wc -l /tmp/bad_ip.list|awk ‘{print $1}‘` if [ $n -ne 0 ] then for ip in `cat /tmp/bad_ip.list` do iptables -I INPUT -s $ip -j REJECT done fi } unblock_ip() { iptables -nvL INPUT |sed `1d` |awk ‘$1<5 {print $8}‘ > /tmp/good_ip.list n=`wc -l /tmp/good_ip.list|awk ‘{print $1}‘` if [ $n -ne 0 ] then for ip in `cat /tmp/good_ip.list` do iptables -D INPUT -s $ip -j REJECT done fi iptables -Z } t=`date +%M` if [ $t =="00" -o $t =="30" ] then unblock_ip block_ip else block_ip fi #算数字 #!/bin/bash x=10 y=21 for i in `seq 0 15` do echo $x x=$[$x+$y] z=$[2**$i] y=$[$y+$z] done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读