-
Notifications
You must be signed in to change notification settings - Fork 2
/
dtstatus
executable file
·75 lines (64 loc) · 2.1 KB
/
dtstatus
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
#! /bin/bash
# Distributed Tools - dtools - dtstatus
# Copyright (C) 2008 Andrés J. Díaz <ajdiaz@connectical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
${DEBUG:+set -x}
DTOOLS_LIB="${DTOOLS_LIB:-/usr/lib/dtools}"
# Some usefull functions to everybody, declared here to be accesible for all
# script and modules. We keep here check functions and error dispatchers.
err () { echo "${R}fail${N}::$(basename $0):$@" >&2 && ${E:+exit $E}; }
req () { type -p "$1" 2>/dev/null >/dev/null; }
lib () { source "${DTOOLS_LIB}/$1" 2>/dev/null >/dev/null; }
cap () { tput "$1" 2>/dev/null >/dev/null; }
# Define colors if capability is present in tty and if -N option is no
# present in command line.
if cap colors && ${opt_N:-true}; then
H=$'\e[0;1m'
N=$'\e[0;0m'
R=$'\e[31;1m'
G=$'\e[32;1m'
fi
# fun: dt_inplace <str>
# txt: remove escapes from dt_replace
dt_inplace ()
{
local r="${1//\\n/\\\\n}"
local r="${r//\\r/\\\\r}"
echo "$r"
}
a_okay=()
a_fail=()
export IFS=':'
while read -r status null dt command hostname message ; do
case "$status" in
*okay*) a_okay[${#a_okay[@]}]="${H}$hostname${N}:$message" ;;
*fail*) a_fail[${#a_fail[@]}]="${H}$hostname${N}:$message" ;;
esac
done
if [ ${#a_okay[@]} -gt 0 ]; then
echo "${G}okay${N}:"
for item in "${a_okay[@]}" ; do
echo -e "\t$(dt_inplace "$item")"
done
echo
fi
if [ ${#a_fail[@]} -gt 0 ]; then
echo "${R}fail${N}:"
for item in "${a_fail[@]}" ; do
echo -e "\t$(dt_inplace "$item")"
done
echo
fi