小练习
编写脚本selinux.sh,实现开启或禁用SELinux功能
[ scripts]$cat selinux.sh #!/bin/bash # STATE=`grep ‘SELINUX\>‘ /etc/selinux/config | grep -v ‘^#‘ | cut -d= -f2` case $1 in start) [ "$STATE" = "enforcing" ] || sed -i ‘/SELINUX/@‘ /etc/selinux/config echo "SELinux is enforcing..." ;; stop) [ "$STATE" = "disabled" ] || sed -i ‘/SELINUX/@‘ /etc/selinux/config echo "SELinux is disabled..." ;; status) echo "SELinux is ${STATE}..." ;; *) echo "Usage:`basename $0` <start|stop|status>" ;; esac
统计/etc/fstab文件中每个文件系统类型出现的次数
[ scripts]$awk ‘/^UUID/{count[$3]++}END{for(i in count){print i,count[i]}}‘ /etc/fstab swap 1 xfs 3
提取出字符串%9&Bdh7dq+YVixp3vpw中的所有数字
[ scripts]$echo "%9&Bdh7dq+YVixp3vpw" | tr -dc ‘[[:digit:]]‘ 05973[ scripts]$ [ scripts]$echo "%9&Bdh7dq+YVixp3vpw" | tr -dc ‘[[:digit:]]‘ |xargs 05973
解决DOS***生产案例:根据web日志或者或者网络连接数,监控当某个IP 并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频 率每隔5分钟。防火墙命令为:iptables -A INPUT -s IP -j REJECT
[ scripts]$cat dos.sh #!/bin/bash # awk ‘{count[$1]++}END{for(i in count){if(count[i]>=100){print i,count[i]}}}‘ /data/scripts/access_log | while read IP COUNT; do echo "${IP}访问了${COUNT}次数..." /usr/sbin/iptables -A INPUT -s ${IP} -j REJECT echo "${IP}被加入到了防火墙..." sed -i "/${IP}/d" /data/scripts/access_log done [ scripts]$crontab -l */5 * * * * /bin/bash /data/scripts/dos.sh
相关推荐
chenchuang 2020-08-01
QiHsMing 2020-06-28
hnllei 2020-06-25
wys 2020-06-18
kerson 2020-06-16
LonelyTraveler 2020-05-29
sixforone 2020-05-28
missingmuch 2020-05-25
jLawrencee 2020-05-19
想个标题偏头痛 2020-05-04
liaochaowu 2020-05-03
RisenWang 2020-05-02
wintelx 2020-04-29
89284553 2020-04-10
老谢的自留地 2020-03-25
Summer的小屋 2020-02-29
wannagonna 2020-02-25
jackalwb 2020-01-29
jiangtie 2020-01-09