-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcable-ping
More file actions
executable file
·44 lines (31 loc) · 888 Bytes
/
cable-ping
File metadata and controls
executable file
·44 lines (31 loc) · 888 Bytes
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
#!/bin/sh -e
# Setup environment with needed environment vars
. /etc/cable/profile
# Command-line parameters
if [ $# != 1 ]; then
echo "Format: $0 user@host"
exit 1
fi
error() {
echo "cable-ping: $@" 1>&2
exit 1
}
emailregex="${CABLE_REGEX}"
cableregex="LIBERTE CABLE [[:alnum:]._-]+"
maxresp=128
addr="$1"
if ! echo x "${addr}" | egrep -q "^x ${emailregex}$"; then
error "unsupported address"
fi
user=`echo "${addr}" | cut -d@ -f1`
host=`echo "${addr}" | cut -d@ -f2`
url=http://"${host}"/"${user}"/request/ver
# Pipe eats curl's error status, if any
resp=`curl -sSfg "${url}" 2>&1 | head -c ${maxresp} | tr -cd '[:alnum:][:blank:]:()/._-'`
if echo x "${resp}" | grep -q "^x curl:"; then
error "communication error: ${resp}"
elif echo x "${resp}" | egrep -q "^x ${cableregex}$"; then
echo "${resp}"
else
error "unexpected output: ${resp}"
fi