From 358017389ef07efcaa056a580d07fcbce9b358ac Mon Sep 17 00:00:00 2001 From: mrbesen Date: Fri, 10 May 2019 01:30:30 +0200 Subject: [PATCH] added service checking --- bot.sh | 11 ++++++++++- services.sh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 services.sh diff --git a/bot.sh b/bot.sh index 30ca692..3845909 100755 --- a/bot.sh +++ b/bot.sh @@ -1,10 +1,19 @@ #!/bin/bash # the main bot script +. func.sh + #hdd usage used=$(df --output=pcent /dev/sda3 | tail -1 | grep -Po "(\\d+)" --color=never) if [ "$used" -gt 50 ]; then - . func.sh echo "warn!" send "warnung%20server%20used%20$used%25%20of%20the%20storage!" fi + +#services +. services.sh +notrunning=$(checkServices "nginx,mysql") +if [ "$notrunning" != "" ]; then + echo "Serive warn!" + send "warnung%20the%20following%20services%20are%20not%20running%20$notrunning" +fi diff --git a/services.sh b/services.sh new file mode 100755 index 0000000..88ef61b --- /dev/null +++ b/services.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +function checkServices { + IFS=',' read -r -a array <<< "$1" + result="" + for service in "${array[@]}" + do + res=$(systemctl is-active "$service") + + if [ "$res" != "active" ]; then + result="$result $service" + fi + done + echo $result +} +