题1
开启/关闭selinux脚本
[root@use02 ~]# cat selinux_set.sh
#!/bin/bash
if [ $# -nt 1 ];then
echo "Usage: selinux_set.sh start|stop"
exit 1
elif [ "$1" == "start" ];then
setenforce 1 &> /dev/null
sed -i 's/^SELINUX=.*/SELINUX=enforcing/g' /etc/selinux/config &> /dev/null
elif [ "$1" == "stop" ];then
setenforce 0 &> /dev/null
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config &> /dev/null
else
echo "Usage: selinux_set.sh start|stop"
fi
题2
统计/etct/fstab的文件系统个数
[root@use02 ~]# cat file_sys.sh
#!/bin/bash
declare -A file_sys
grep -Ev '^#|^$' /etc/fstab | awk '{print $3}' > /tmp/log.txt
while read line;do
name=${line}
let file_sys[${name}]++
done < /tmp/log.txt
for i in ${!file_sys[*]};do
echo "${i}:${file_sys[${i}]}"
done
题3
取出字符串中的数字
[root@use02 ~]# echo "Yd$C@M05MB%9&Bdh7dq+YVixp3vpw" | tr -dc [0-9]
05973
题4
统计对网页的访问次数,并用防火墙进行管理
[root@use04 ~]# yum install httpd
[root@use04 ~]# echo "test" > /var/www/html/index.html
[root@use04 ~]# systemctl start httpd
[root@use04 ~]# cat httpd_count.sh
#!/bin/bash
declare -A access_num
awk '{print $1}' /var/log/httpd/access_log > /tmp/access.log
while read line;do
ip=$line
let access_num[${ip}]++
done < /tmp/access.log
for i in ${!access_num[*]};do
if [ ${access_num[$i]} -gt 10 ];then
iptables -t filter -I INPUT -s ${i} -j DROP
fi
done
[root@use04 ~]# crontab -e
*/5 * * * * /bin/bash /root/httpd_count.sh > /dev/null