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
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Bash:用文件名中的空格扩展大括号和glob
- vim – 如何干净地编辑diff/patch文件?是否有补丁文件编辑
- BootStrap入门教程(一)之可视化布局
- angularjs – 角度标签 – 可排序/可移动
- vim – 如何将所有匹配的行混入一个缓冲区?
- Bootstrap 前端框架 遇到的问题 解决方案
- Scala IDE 4.0.0认为开箱即用的Play Framework 2.3.7程序有
- bash – 如何在Makefile操作中使用shell变量?
- 重复eval T => scala.concurrent.Future [T]到一个进程[?,
- Angular2 RC6管道.我可以在与我的组件相同的.ts文件中声明管