#!/bin/bash # 持续监控应用状态,直到应用运行正常 whiletrue do if systemctl status myapp | grep -q "active (running)"; then break fi sleep 10 done
持续检查服务器负载
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash # 持续检查服务器负载,如果负载过高则发送警报邮件 whiletrue do load=$(uptime | awk '{print $10}') if [ $(echo"$load > 1.0" | bc -l) -eq 1 ]; then echo"Warning: server load is high: $load" | mail -s "Server load warning" admin@example.com fi sleep 300 done
持续检查应用日志
1 2 3 4 5 6 7 8 9 10
#!/bin/bash # 持续检查应用日志,如果有错误日志则发送警报邮件 whiletrue do if grep -q "Error" /var/log/myapp.log; then echo"Warning: Error log found in myapp.log" | mail -s "Application error" admin@example.com fi sleep 600 done