-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.sh
executable file
·79 lines (61 loc) · 1.57 KB
/
stats.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
MINE="luna Big-Macintosh raspberrypi Applejack Braeburn"
THEIRS="ironduke grid.cs.gsu"
# use GNU sed
source .env
# because non-login non-interactive mode doesn't have gnu coreutils installed via homebrew in its $PATH
sed() {
if hash gsed 2>/dev/null;
then
gsed "$@"
else
env sed "$@"
fi
}
test() {
if [[ `ssh -q $1 exit 2>/dev/null` -eq 0 || `ping -c 1 $1 2>/dev/null` -eq 0 ]]
then
echo "$LIGHT_BLUE$1$DEFAULT: up"
else
echo "$RED$1: down$DEFAULT"
fi
}
export -f test
echo -n $THEIRS | parallel -k -d " " --no-notice test {}
updates() {
if [[ `brew --version 2>/dev/null` ]]
then
brew outdated | wc -w
elif [[ `apt-get --version` ]]
then
apt-get -s upgrade | grep -Po --color=never "^\d+ (?=upgraded)"
fi
}
export -f sed updates
source ~/sh/conkify.sh $1
if [[ $1 == "geektool" ]]
then
export LIGHT_BLUE="$CYAN"
fi
export sedexp="s/.*load averages\?: [0-9]\+\.[0-9]\+,\? \([0-9]\+\.[0-9]\+\).*/\1/g"
info(){
if [[ $1 == $(hostname | sed -e "s/.local$//g") ]]
then
UPTIME=$(uptime | sed "$sedexp")
else
UPTIME=$(timeout 5 ssh $1 "uptime" 2>/dev/null || return 1) || (echo -e "$RED$1: unreachable$DEFAULT" && return 1) || return 1
fi
echo -en "$LIGHT_BLUE$1$DEFAULT: "
UPTIME=$(echo $UPTIME | sed "$sedexp")
if [[ $1 == $(hostname | sed -e "s/.local$//g") ]]
then
UPDATES=$(updates)
else
UPDATES=$(ssh $1 "$(typeset -f updates); updates")
fi
UPDATES=${UPDATES//[[:blank:]]/}
if [[ ! $UPDATES == 0 ]]; then UPTIME="$UPTIME, $UPDATES updates"; fi
echo "$UPTIME"
}
export -f info
echo -n $MINE | parallel -k -d " " --no-notice info {}