#!/usr/bin/bash
#
# Send stdout of some commands to monitoring server.
# Collect the reports with 'nc -u -k -l 1234' on 'sendto'.
# Use /bin/nc.openbsd, /bin/nc.traditional seems not to work.
#
set -eu

sendto="collector.steinbeis.schule 1234"

cmds=(
    'uname -a'
    'uptime'
    'w'
    'ls -d --full-time /home/ansible/.ansible/tmp/'
    'ip route list default'
)
#    'ip addr show'
#    'apt list --upgradeable -o Apt::Cmd::Disable-Script-Warning=true'

r="$HOSTNAME: ------- $(date --rfc-3339=seconds) -------
$(for c in "${cmds[@]}" ; do echo "$c"; $c | sed 's/^/  /' ; done | sed "s/^/$HOSTNAME: /")
## -------------------------------------------------"
echo "$r" | nc -w 1 -u $sendto