diff --git a/.local/bin/bgp-check b/.local/bin/bgp-check new file mode 100755 index 0000000..a93d47e --- /dev/null +++ b/.local/bin/bgp-check @@ -0,0 +1,58 @@ +#!/bin/bash + +################################################################################ +# +# Marcin Wozniak +# Last edit: 2023-05-05 +# +# shellcheck disable=1091 +################################################################################ + +set -u +set -e + +# Colours +RED='\033[0;31m' +GREEN='\033[0;0;32m' +NC='\033[0m' + +ADDR=$1 +LOG_FILE="bgp-$ADDR-$(date -I).log" + +function timestamp() { + echo -e "${GREEN}[+]${NC} $(date +'%F %T') [INFO] $*" +} + +function err() { + echo -e "${RED}[-] $(date +'%F %T') [ERROR] $*${NC}" >&2 +} + +function command_start() { + timestamp "Command $* has been started." + if ! "$@"; then + err "Command $* went wrong." + exit 0 + fi + timestamp "Command $* has been ended." +} + +function bgpcheck() { + timestamp "CHECKING BGP FOR $ADDR at RT.IR9.AMS.NL.retn.net" + curl --silent \ + "https://lg.retn.net/cgi/LG.cgi?r=87&p=4&q=b&a=$ADDR" | + sed '/table>/d;//d;/td>/d;/query/d;/html/d;/head/d;/title/d;/img/d;/body/d;/center/d;/h2/d;/

/d;/


/d;//d;/td>/d;/query/d;/html/d;/head/d;/title/d;/img/d;/body/d;/center/d;/h2/d;/

/d;/


&2 +} + +function command_start() { + timestamp "Command $* has been started." + if ! "$@"; then + err "Command $* went wrong." + # sendmailerr + exit 0 + fi + timestamp "Command $* has been ended." +} + +function pinger() { + ping "$ADDR" | while read pong; do timestamp "$pong"; done +} + +function main() { + command_start pinger +} + +main | tee "$LOG_FILE"