-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssh-status.1m.sh
More file actions
34 lines (32 loc) · 1.01 KB
/
Copy pathssh-status.1m.sh
File metadata and controls
34 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
#
# <bitbar.title>SSH Status</bitbar.title>
# <bitbar.version>v0.1.0</bitbar.version>
# <bitbar.author>Olivier Tille</bitbar.author>
# <bitbar.author.github>oliviernt</bitbar.author.github>
# <bitbar.image></bitbar.image>
# <bitbar.desc>Continuously checks if hosts are available for ssh connection</bitbar.desc>
# <bitbar.dependencies>Bash</bitbar.dependencies>
#
# SSH Status plugin
# by Olivier Tille (@oliviernt)
#
# Continuously checks if hosts are available for ssh connection on port 22
HOSTS=("example1.com" "example2.com")
head="ssh status"
body=""
errors=0
for host in "${HOSTS[@]}"; do
nc -z -G 2 "$host" 22 &> /dev/null
if [ "$?" -eq 0 ]; then
body="$body\n☀️ $host is up | color=green bash=ssh param1=$host"
else
body="$body\n⛈ $host looks down from here | color=red bash=ssh param1=$host"
errors=$(($errors + 1))
fi
body="$body\n---"
done
echo -n "$head"
[ "$errors" -eq 0 ] || echo -n " ($((${#HOSTS[@]}-$errors))/${#HOSTS[@]}) | color=red"
echo -e "\n---"
echo -e "$body"