#!/bin/bash

if [ $# -ne 0 ]; then
  >&2 echo 'check-if-bareos-backup-is-running: too many arguments'
  exit 2
fi

if cat /proc/net/tcp* \
| awk '{print $2 " " $3}' \
| grep -vw '\(000000000000000000000000\)\?00000000:0000' \
| tr ' ' '\n' \
| grep -F : \
| cut -d: -f2 \
| grep -qxiF '238F'; then
  >&2 echo 'bareos-fd is connected to bareos-sd'
  exit 1
else
  >&2 echo 'bareos-fd is not connected to bareos-sd'
fi