Skip to content

Instantly share code, notes, and snippets.

@jemsgit
Last active May 14, 2026 16:18
Show Gist options
  • Select an option

  • Save jemsgit/2c3676b04e8102aba6aa6d0a4983c5e7 to your computer and use it in GitHub Desktop.

Select an option

Save jemsgit/2c3676b04e8102aba6aa6d0a4983c5e7 to your computer and use it in GitHub Desktop.
#!/bin/bash
# === Настройки ===
BOT_TOKEN=""
CHAT_ID=""
HOSTNAME=$(hostname)
get_cpu_load() {
top -bn2 | grep "Cpu(s)" | tail -n1 | awk -F',' '{print 100-$4}' | awk '{printf "%.1f\n", $1}'
}
# === Сбор метрик ===
CPU_LOAD=$(get_cpu_load)
MEMORY=$(free -h | awk '/Mem:/ {print $3 " / " $2}')
DISK=$(df -h / | awk 'NR==2 {print $4 " свободно из " $2}')
UPTIME=$(uptime -p)
SERVER_IP=$(hostname -I | awk '{print $1}')
# === Формирование сообщения ===
MESSAGE="🖥️ *Отчёт с сервера ${HOSTNAME}*
🌐 IP: ${SERVER_IP}
⏱️ Аптайм: ${UPTIME}
🔥 CPU: ${CPU_LOAD}
💾 RAM: ${MEMORY}
📀 Disk: ${DISK}"
# === Отправка в Telegram ===
curl -s -X POST "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage" \
-d chat_id="${CHAT_ID}" \
-d parse_mode="Markdown" \
-d text="${MESSAGE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment