1、编写脚本selinux.sh,实现开启或禁用selinux功能
#!/bin/bash
read -p "please input character set selinux for {start|stop} :" s
se=$(sed -rn 's@^SELINUX=(.*)@\1@'p /etc/selinux/config)
if [ $s == 'start' ];then
if [ $se == 'enforcing' ];then
echo "selinux status is enforcing"
elif [ $se == 'disabled' ];then
sed -ri 's@^SELINUX=(.*)@SELINUX=enforcing@' /etc/selinux/config && echo "selinux is start "
fi
elif [ $s == 'stop' ];then
if [ $se == 'disabled' ];then
echo "selinux status is disabled"
elif [ $se == 'enforcing' ];then
sed -ri 's@^SELINUX=(.*)@SELINUX=disabled@' /etc/selinux/config && echo "selinux is stop"
fi
fi
2、统计/etc/fstab文件中每个文件系统类型出现的次数
cat /etc/fstab|grep "^/" |awk '{print $3}'|uniq -c
3、提取出字符串Yd$C@M05MB%9&Bdh7dq+YVixp3vpw中的所有数字
echo 'Yd$C@M05MB%9&Bdh7dq+YVixp3vpw' > ll.txt
cat ll.txt |grep -o [0-9]
结果:
4、解决DOS攻击生产案例:根据web日志或者或者网络连接数,监控当某个IP 并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频 率每隔5分钟。防火墙命令为:iptables -A INPUT -s IP -j REJECT
#!/bin/bash
cat /data/access_log | awk '{IP[$1]++}END{for(i in IP){print i,IP[i]}}' > /tmp/hosts.txt
while read ip number;do
if [ $number -gt 100 ] ;then
iptables -A INPUT -s $ip -j REJECT
echo "from $ip $number rejected" >> /tmp/reject.txt
fi
done < /tmp/hosts.txt
设定5分钟启动
crontab -e
*/5 * * * * /root/checkip.sh