info about reboot extended

This commit is contained in:
Pavel Muhortov 2023-12-24 15:15:03 +03:00
parent b2743157eb
commit 642b1bb105
2 changed files with 176 additions and 32 deletions

View File

@ -11,14 +11,87 @@
### END INIT INFO ### END INIT INFO
start() { start() {
sleep 30 TXT_MSG="[System States] $(cat /etc/hostname): OS has been rebooted"
REL=$(grep 'PRETTY_NAME' /etc/os-release | cut -d= -f2)
if [ -n "${REL}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- RELEASE:
${REL}
END
)
fi
KER=$(uname -srm)
if [ -n "${KER}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- KERNEL:
${KER}
END
)
fi
NET=$(ip a | grep 'inet' | grep -v -e '127.0.0.1/8' -e '::1/128' \
| awk '{print $2}')
if [ -n "${NET}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- NETWORK:
${NET}
END
)
fi
CPU=$(grep 'model name' /proc/cpuinfo | cut -d':' -f2- | cut -d' ' -f2-)
if [ -n "${CPU}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- CPUs:
${CPU}
END
)
fi
MEM=$(grep /proc/meminfo \
-e 'MemTotal' -e 'MemAvailable' -e 'MemFree' \
-e 'SwapTotal' -e 'SwapFree' \
| numfmt --field 2 --from-unit=Ki --to=iec | sed 's/ kB//g')
if [ -n "${MEM}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- MEMORY:
${MEM}
END
)
fi
DRI=$(LC_ALL=en_US.UTF-8 df -h --output=source,fstype,size,pcent,target \
-x tmpfs -x devtmpfs -x squashfs)
if [ -n "${DRI}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- DRIVES:
${DRI}
END
)
fi
sleep 15
python3 /usr/local/bin/sendmail.py \ python3 /usr/local/bin/sendmail.py \
--smtp "$(cat /usr/local/bin/sendmail.config | grep "smtp=" | cut -d= -f2)" \ --smtp "$(grep "smtp=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
-u "$(cat /usr/local/bin/sendmail.config | grep "from=" | cut -d= -f2)" \ -u "$(grep "from=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
-p "$(cat /usr/local/bin/sendmail.config | grep "pass=" | cut -d= -f2)" \ -p "$(grep "pass=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
-d "$(cat /usr/local/bin/sendmail.config | grep "dest=" | cut -d= -f2)" \ -d "$(grep "dest=" /usr/local/bin/sendmail.config | cut -d= -f2)" \
--subj "[System States] $(cat /etc/hostname): computer has been rebooted" \ --subj "[System States] $(cat /etc/hostname): OS has been rebooted" \
--text "$(w)" \ --text "${TXT_MSG}" \
>> /dev/null 2>&1 & >> /dev/null 2>&1 &
} }
@ -38,7 +111,7 @@ case "$1" in
start start
;; ;;
*) *)
echo "Usage: $0 {start|stop|restart}" printf "%s\n" "Usage: $0 {start|stop|restart}"
esac esac
exit 0 exit 0

View File

@ -15,7 +15,78 @@ start() {
SILENCE="$(grep "SILENCE=" /usr/local/bin/sendtelegram.config | cut -d= -f2)" SILENCE="$(grep "SILENCE=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
CHAT_ID="$(grep "CHAT_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)" CHAT_ID="$(grep "CHAT_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
THRD_ID="$(grep "THRD_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)" THRD_ID="$(grep "THRD_ID=" /usr/local/bin/sendtelegram.config | cut -d= -f2)"
TXT_MSG="[System States] $(cat /etc/hostname): computer has been rebooted" TXT_MSG="[System States] $(cat /etc/hostname): OS has been rebooted"
REL=$(grep 'PRETTY_NAME' /etc/os-release | cut -d= -f2)
if [ -n "${REL}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- RELEASE:
${REL}
END
)
fi
KER=$(uname -srm)
if [ -n "${KER}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- KERNEL:
${KER}
END
)
fi
NET=$(ip a | grep 'inet' | grep -v -e '127.0.0.1/8' -e '::1/128' \
| awk '{print $2}')
if [ -n "${NET}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- NETWORK:
${NET}
END
)
fi
CPU=$(grep 'model name' /proc/cpuinfo | cut -d':' -f2- | cut -d' ' -f2-)
if [ -n "${CPU}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- CPUs:
${CPU}
END
)
fi
MEM=$(grep /proc/meminfo \
-e 'MemTotal' -e 'MemAvailable' -e 'MemFree' \
-e 'SwapTotal' -e 'SwapFree' \
| numfmt --field 2 --from-unit=Ki --to=iec | sed 's/ kB//g')
if [ -n "${MEM}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- MEMORY:
${MEM}
END
)
fi
DRI=$(LC_ALL=en_US.UTF-8 df -h --output=source,fstype,size,pcent,target \
-x tmpfs -x devtmpfs -x squashfs)
if [ -n "${DRI}" ]; then
TXT_MSG=$(cat <<-END
${TXT_MSG}
--- DRIVES:
${DRI}
END
)
fi
sleep 15 sleep 15
if [ -z "${THRD_ID}" ]; then if [ -z "${THRD_ID}" ]; then
@ -35,7 +106,7 @@ start() {
} }
stop() { stop() {
pkill -f curl -s -o /dev/null -X POST -d chat_id="${CHAT_ID}" pkill -f "curl -s -o /dev/null -X POST -d chat_id=${CHAT_ID}"
} }
case "$1" in case "$1" in