blob: 5af7f3b5d67006fcad53ab67a1622115f91531ce [file] [log] [blame] [raw]
http_post() {
if [ $# != 2 ]; then
echo "Usage: http_post <url> <data>" 1>&2
return 255
fi
#curl "$1" --request POST --data-binary "$2"
wget --no-verbose "$1" --post-data "$2"
}
get_ip_address() {
if [ $# != 1 ]; then
echo "Usage: get_ip_address <interface>" 1>&2
return 255
fi
ifconfig "$1" | grep -Eo -m 1 'inet[ a-z:]+172\.20\.0\.[0-9]{3}' | sed -r 's/^inet[ a-z:]+//'
return 0
}
set_hostname_from_interface() {
HOSTNAME="`get_ip_address \"$1\"`"
if [ -z "$HOSTNAME" ]; then
printf "Cannot get IP address from interface '%s'\\n" "$1" 1>&2
exit 1
fi
}
load_config_file() {
[ -f "$1" ] || return
eval "`grep -Eo '^[A-Z0-9_]+=[-A-Za-z0-9_@" .:/\\]+' \"$1\"`"
}
handle_command_line_options() {
while getopts i:I:n: c
do case "$c" in
i)
INTERVAL="$OPTARG"
;;
I)
INTERFACE="$OPTARG"
;;
n)
HOSTNAME="$1"
;;
\?)
printf "Usage: %s [-i <interval>] [-I <interface>] [-n <hostname>]\\n" "$0" 1>&2
exit 255
;;
esac done
}