1、编写脚本selinux.sh,实现开启或禁用SELinux功能
echo "Change Selinux status........"
echo "The Selinux state is now $(getenforce)"
if [ "$(getenforce)" == "Disabled" ];then
echo "After you select 0 or 1,you must reboot system...."
fi
cat <<EOF
0) Change the Selinux state to "Permissive"
1) Change the Selinux state to "Enforcing"
2) Change the Selinux state to "Disabled"
EOF
read -p "Please Input (0,1,2):" num
if [ "$(getenforce)" == "2" ];then
echo "Selinux state is $(getenforce)"
fi
case $num in
0)
sed -ri 's/(^SELINUX=).*/\1enforcing/' /etc/sysconfig/selinux
echo "The Selinux state is Changed to Enforcing"
;;
1)
sed -ri 's/(^SELINUX=).*/\1permissive/' /etc/sysconfig/selinux
echo "The Selinux state is Changed to Pnforcing" ;;
2)
sed -ri 's/(^SELINUX=).*/\1disabled/' /etc/sysconfig/selinux
echo "The Selinux state is Changed to Disabled....... Your must reboot system" ;;
*)
echo "Your Input Error!!!" ;;
esac
2、统计/etc/fstab文件中每个文件系统类型出现的次数:
[root@Centos-7 ~]#awk '/^[^#]/{type[$3]++}END{for(i in type) {print i,type[i]}}' /etc/fstab
3、提取出字符串Yd$C@M05MB%9&Bdh7dq+YVixp3vpw中的所有数字
[root@Centos-7 ~]#echo 'Yd$C@M05MB%9&Bdh7dq+YVixp3vpw' | awk 'gsub(/[^[:digit:]]/,"", $0)'
05973
4、解决DOS攻击生产案例:根据web日志或者或者网络连接数,监控当某个IP 并发连接数或者短时内PV达到100,即调用防火墙命令封掉对应的IP,监控频 率每隔5分钟。防火墙命令为:iptables -A INPUT -s IP -j REJECT
[root@Centos-7 ~]#awk '{ip[$1]++}END{for(i in ip){if(ip[i]>=10) {system("iptables -A INPUT -s "i" -j REJECT")} }}' /varlog/httpd/access_log