1紊馏、編寫腳本selinux.sh料饥,實現(xiàn)開啟或禁用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、統(tǒng)計/etc/fstab文件中每個文件系統(tǒng)類型出現(xiàn)的次數(shù):
[root@Centos-7 ~]#awk '/^[^#]/{type[$3]++}END{for(i in type) {print i,type[i]}}' /etc/fstab
3朱监、提取出字符串Yd$C@M05MB%9&Bdh7dq+YVixp3vpw中的所有數(shù)字
[root@Centos-7 ~]#echo 'Yd$C@M05MB%9&Bdh7dq+YVixp3vpw' | awk 'gsub(/[^[:digit:]]/,"", $0)'
05973
4岸啡、解決DOS攻擊生產(chǎn)案例:根據(jù)web日志或者或者網(wǎng)絡連接數(shù),監(jiān)控當某個IP 并發(fā)連接數(shù)或者短時內PV達到100赫编,即調用防火墻命令封掉對應的IP巡蘸,監(jiān)控頻 率每隔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