## Bu dosya ansible tarafindan yonetilmektedir!
## Burada yapilan degisikliklerin uzerine yazilir!!
{{ ansible_managed }}

#!/bin/bash

EOF=
local RESULT;

while true;
do

RESULT=$(/usr/bin/ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ahtapotops@{{ gkts['server'] }} -p {{ gkts['port'] }} "/bin/bash -c 'head -n 1 /var/opt/ahtapot-gkts/gkts && sed '1d' /var/opt/ahtapot-gkts/gkts > /var/opt/ahtapot-gkts/.gktstmp ; mv /var/opt/ahtapot-gkts/.gktstmp /var/opt/ahtapot-gkts/gkts'")

if [[ $RESULT = $EOF ]]
then
	/usr/bin/logger -p '{{ gkts['logseverity'] }}' "Gkts file is processed ( EOF )"
	exit 0
else
	/usr/bin/logger -p '{{ gkts['logseverity'] }}' "Rule $(echo $RESULT | cut -d'"' -f2) is processing for $(echo $RESULT | cut -d'"' -f1)"
	/usr/bin/ssh ahtapotops@$(echo $RESULT | cut -d'"' -f1) -p {{ gkts['port'] }} "/usr/bin/sudo /bin/bash -c '$(echo $RESULT | cut -d'"' -f2)' "
fi

done
