#!/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin # 1 hour lock_delay=3600 # _public script is more permissive and complex, use the stric and simple script by default # deploy either the one or the other as necessary (define public_ssh with ansible) if [[ -x /usr/local/bin/check_attackers.bash ]]; then check_script=/usr/local/bin/check_attackers.bash elif [[ -x /usr/local/bin/check_attackers_public.bash ]]; then check_script=/usr/local/bin/check_attackers_public.bash else echo please deploy either check_attackers.bash or check_attackers_public.bash exit 1 fi [[ ! -x `which dos2unix` ]] && echo install dos2unix first && exit 1 [[ ! -x `which slack_webhook3.bash` ]] && echo deploy slack_webhook3.bash first && exit 1 time=`date +%s` output=`$check_script` if [[ $? -ne 0 ]]; then if [[ -f /tmp/check_attackers.lock ]]; then previous_time=`cat /tmp/check_attackers.lock` # lock delay has not been reached yet (( seconds_passed = time - previous_time )) if (( seconds_passed < lock_delay )); then (( seconds_left = lock_delay - seconds_passed )) echo previous lock is still active for $seconds_left seconds exit 0 fi unset previous_time fi echo -n writing new lock /tmp/check_attackers.lock ... echo $time > /tmp/check_attackers.lock && echo done # self-verbose slack_webhook3.bash check_attackers@$HOSTNAME "$output" fi