1.
[root@localhost /]# vim /etc/s-nail.rc
set from=1742470956@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=1742470956@qq.com
set smtp-auth-password=wgvuzslqwghnccjc
set smtp-auth=login
[root@localhost /]# echo "testmail" | mail -s "testmail" 1742470956@qq.com‘
root@localhost /]# vim disk1.sh
#!/bin/bash
disk=`df -m | grep -w "/" | tr -s " " | cut -d " " -f4`
str1="warning:disk space less than 20G!"
if [ "$disk" -lt 20000 ]
then
echo "$str1" | mail -s "$str1"1742470956@qq.com
fi
[root@localhost /]# vim /etc/crontab
0 0 * * * root /bin/bash /root/disk1.sh
2.
[root@localhost /]# vim web1.sh
#!/bin/bash
ps=`ps -ef | grep httpd | grep -v grep | wc -l`
if [ "$ps" -gt 0 ];then
echo "Httpd is already running"
else
echo "Httpd not started,waiting……"
yum install httpd -y > /dev/null
systemctl start httpd
systemctl start firewalld
firewall-cmd --permanent --
zone=public --add-service=http > /dev/null
firewall-cmd --permanent --
zone=public --add-port=80/tcp >/dev/null
firewall-cmd --reload > /dev/null
echo "Httpd is already running"
fi
[root@localhost /]# ss -lntup | grep -w 80 | wc -l
1
[root@localhost /]# bash web1.sh
Httpd is already running
3.
[root@localhost /]# vim web2.sh
#!/bin/bash
cur1 -s 192.168.122.1 > /dev/null
if (($?==0))
then
echo "web server is running."
else
echo "Web not accessible"
exit 12
fi
[root@localhost /]# bash web2.sh
web server is running