为远程服务器增加rsyncd的信任IP

#! /bin/bash

echo "Please input the new ip:"
read ip
echo "please input the web ip:"
read webip
echo "please input the db ip:"
read dbip

ip1=`echo $ip|awk -F'.' '{print $1"."$2"."$3}'`
ip2=$ip1.0\/24

change(){
    sed  -i "s#\(^hosts.*\)#& $ip2#g" $1
}

addip() {
    scp $1:/etc/rsyncd.conf /tmp/$1-rsyncd.conf >/dev/null
    if grep -q "$ip2" /tmp/$1-rsyncd.conf; then
        echo "$1 has been added the new ip."
    else
        change /tmp/$1-rsyncd.conf
        scp /tmp/$1-rsyncd.conf $1:/etc/rsyncd.conf >/dev/null && echo "$1 add new ip done."
    fi
}

addip $webip
addip $dbip
if grep -q $ip2 /etc/rsyncd.conf; then
    echo ""
else
    change /etc/rsyncd.conf
fi

添加新评论 »