diff --git a/registry/scripts/registry.sh b/registry/scripts/registry.sh old mode 100644 new mode 100755 index e19427a7b7946c3fe75dd99bbff1edf17d6e79bb..838be8d165eb9f9ac80041366c45b1d21494f968 --- 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