From 2dc3716ce0d8b2063801c9bcdcb86d72298d0e36 Mon Sep 17 00:00:00 2001 From: David Beniamine <david.beniamine@tetras-libre.fr> Date: Fri, 14 Sep 2018 10:11:56 +0200 Subject: [PATCH] Timestamp hosts --- registry/scripts/registry.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) mode change 100644 => 100755 registry/scripts/registry.sh diff --git a/registry/scripts/registry.sh b/registry/scripts/registry.sh old mode 100644 new mode 100755 index e19427a..838be8d --- a/registry/scripts/registry.sh +++ b/registry/scripts/registry.sh @@ -22,15 +22,24 @@ getip(){ } IP=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1) -# broadcast=$(ip a | awk '/inet.*eth1/ {print $4}' | cut -d / -f 1) -# subnet=$(ip a | awk '/inet.*containers/ {print $2}' | cut -d / -f 1 | cut -d . -f 1-3) -# host=$subnet.51 port=9998 conf_dir="/etc/registry" +conf_file="$conf_dir/hosts" if [ ! -d $conf_dir ] then + # Init mkdir $conf_dir +else + # Clean + while read line + do + if [ "$(echo $line | cut -d ' ' -f 1)" -gt "$(date -d '-6 month' +%Y%m%d)" ] + then + LINES="$LINES\n$(date +%Y%m%d) $(echo $line | cut -d ' ' -f 2-)" + fi + done < $conf_file + echo $LINES > $conf_file fi while true @@ -38,7 +47,7 @@ do line=`netcat -l $IP $port` if [ $(echo "$line" | egrep -c "^([0-9a-f]{2}:?){6} .*$") -eq 1 ] then - echo $line >> $conf_dir + echo "$(date +%Y%m%d) $line" >> $conf_file fi done -- GitLab