-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost_status.in
165 lines (158 loc) · 3.56 KB
/
host_status.in
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/bin/sh
#
# $Id: host_status.in,v 1.3 2024-04-21 23:31:08+05:30 Cprogrammer Exp mbhangui $
#
set_command1()
{
if [ -n "$LCD_FIFO" ] ; then
cmd1="/bin/cat > $LCD_FIFO"
return 0
elif [ -n "$LCD_HOST" ] ; then
if [ -z "$LCD_PORT" ] ; then
LCD_PORT=1806
fi
cmd1="nc -w 1 -u $LCD_HOST $LCD_PORT"
return 0
fi
if [ -d /run ] ; then
lcdfifo="/run/lcd-daemon/lcdfifo"
elif [ -d /var/run ] ; then
lcdfifo="/var/run/lcd-daemon/lcdfifo"
else
lcdfifo="/tmp/lcd-daemon/lcdfifo"
fi
if [ -p $lcdfifo ] ; then
cmd1="/bin/cat > /run/lcd-daemon/lcdfifo"
return 0
elif [ -x /usr/bin/nc ] ; then
if [ -n "$LCD_HOST" ] ; then
lcdhost=$LCD_HOST
else
lcdhost=$(grep lcdhost /etc/hosts|awk '{print $1}')
fi
if [ -z "$LCD_PORT" ] ; then
LCD_PORT=1806
fi
if [ -n "$lcdhost" ] ; then
cmd1="nc -w 1 -u $lcdhost $LCD_PORT"
return 0
fi
fi
return 1
}
set_command2()
{
if [ -n "$NOTIFY_FIFO" ] ; then
cmd2="/bin/cat > $NOTIFY_FIFO"
return 0
elif [ -n "$NOTIFY_HOST" ] ; then
if [ -z "$NOTIFY_PORT" ] ; then
NOTIFY_PORT=1807
fi
cmd2="nc -u $NOTIFY_HOST $NOTIFY_PORT"
return 0
fi
if [ -d /run ] ; then
notifyfifo="/run/notify-desktop/notify-fifo"
elif [ -d /var/run ] ; then
notifyfifo="/var/run/notify-desktop/notify-fifo"
else
notifyfifo="/tmp/notify-desktop/notify-fifo"
fi
if [ -p $notifyfifo ] ; then
cmd2="/bin/cat > /run/notify-desktop/notify-fifo"
return 0
elif [ -x /usr/bin/nc ] ; then
if [ -n "$NOTIFY_HOST" ] ; then
notifyhost=$NOTIFY_HOST
else
notifyhost=$(grep notifyhost /etc/hosts|awk '{print $1}')
fi
if [ -z "$NOTIFY_PORT" ] ; then
NOTIFY_PORT=1807
fi
if [ -n "$notifyhost" ] ; then
cmd2="nc -u $notifyhost $NOTIFY_PORT"
return 0
fi
fi
return 1
}
if [ $# -ne 1 ] ; then
exit 1
fi
set_command1
set_command2
case "$1" in
load)
if [ -n "$cmd1" ] ; then
echo "Sending load information to LCD $cmd1"
load=$(cat /proc/loadavg|awk '{print $1" "$2" "$3}')
echo "0 0 3:Load $load" | sh -c "$cmd1"
if [ -n "$LCD_FIFO" ] ; then
sleep 0.5
fi
echo "1 0 0:$(hostname -I)" | sort -u | sh -c "$cmd1"
echo "2 0 0:$(date +"%d-%m-%y %H:%M:%S")" | sh -c "$cmd1"
echo "3 0 0:$(uname -n) On" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
echo "Sending load information desktop notification $cmd2"
load=$(cat /proc/loadavg|awk '{print $1" "$2" "$3}')
(
printf "summary:host-status\n"
printf "body:Load $load\n"
printf "body:\"$(hostname -I | sort -u)\"\n"
printf "body: Boot complete for %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
PowerOff)
if [ -n "$cmd1" ] ; then
echo "3 0 3:$(uname -n) PowerOff" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
(
printf "summary:host-status\n"
printf "body: PowerOff %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
MusicOff)
if [ -n "$cmd1" ] ; then
echo "3 0 3:$(uname -n) MusicOff" | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
(
printf "summary:host-status\n"
printf "body: MusicOff %s\n" $(hostname)
) | sh -c "$cmd2"
fi
;;
*)
if [ -n "$cmd1" ] ; then
echo "Sending text to LCD $cmd1"
echo $1 | sh -c "$cmd1"
fi
if [ -n "$cmd2" ] ; then
echo "Sending desktop notification $cmd2"
(
printf "summary: host-status\n"
printf "body:$1\n"
) | sh -c "$cmd2"
fi
;;
esac
#
# $Log: host_status.in,v $
# Revision 1.3 2024-04-21 23:31:08+05:30 Cprogrammer
# added desktop notification to notifyhost or notify-fifo
#
# Revision 1.2 2024-03-23 02:02:44+05:30 Cprogrammer
# add delay when resetting LCD display
# eliminate duplicate ip addresses
#
# Revision 1.1 2023-06-30 17:09:52+05:30 Cprogrammer
# Initial revision
#
#