Скрипт проверки нагрузки load average:
#!/bin/bash loadavg=`uptime | awk '{print $10+0}'` thisloadavg=`echo $loadavg|awk -F \. '{print $1}'` if [ "$thisloadavg" -ge "2" ]; then echo "Busy - Load Average $loadavg ($thisloadavg) " top -bn 1 else echo "Okay - Load Average $loadavg ($thisloadavg) " fi
Скрипт проверки статуса apache (centos):
#!/bin/bash ps cax | grep httpd 2>/dev/null 1>/dev/null if [ $? -eq 0 ]; then echo "HTTPD is running." else echo "HTTPD is not running." fi
Если ubuntu, то:
#!/bin/bash ps cax | grep apache2 2>/dev/null 1>/dev/null if [ $? -eq 0 ]; then echo "HTTPD is running." else echo "HTTPD is not running." fi
Таким образом можно проверять любые сервисы, например nginx:
#!/bin/bash ps cax | grep nginx 2>/dev/null 1>/dev/null if [ $? -eq 0 ]; then echo "NGINX is running." else echo "NGINX is not running." fi
Или mysql:
#!/bin/bash ps cax | grep mysql 2>/dev/null 1>/dev/null if [ $? -eq 0 ]; then echo "MYSQL is running." else echo "MYSQL is not running." fi
По аналогичному скрипту можно настроить отправку уведомлений в telegram если к примеру load average высокое:
#!/bin/bash loadavg=$(uptime | awk '{print $10+0}') thisloadavg=$(echo $loadavg|awk -F \. '{print $1}') if [ "$thisloadavg" -ge "2" ] then ID_USER=849489845 TOKEN_BOT=999999999:Afwe98yUw3kj-O-8NdwIOIwnp2452131 in=$(echo -e "HARD LOAD AVERAGE") message=$in curl -s -X POST "https://api.telegram.org/bot"$TOKEN_BOT"/sendMessage" -F chat_id=$ID_USER -F text="$message" fi
Где, ID_USER — ВАШ ID
TOKEN_BOT — токен бота.