while 读文件一行问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_29173167/article/details/82784643
#!/usr/bin/env bash
FILE=$1

while read LINE;do
   ip=`echo $LINE |awk '{print $1}'`
   asset=`echo $LINE |awk '{print $2}'`
   hostname=`echo $LINE |awk '{print $3}'`
   asset_org=`pgm $ip 'cat /etc/sinainstall.conf' </dev/null|grep asset|cut -d'=' -f2` 
   if [ "$asset_org" == "$asset" ];then
    pgm $ip "sudo hostnamectl set-hostname $hostname && sudo sed -i -r 's@HOSTNAME=.*@HOSTNAME=$hostname@g' /etc/sysconfig/network" < /dev/null
    [ $? -eq 0 ] && echo "$ip <ok> $hostname" || echo "$ip <fail> $hostname" 
   else
    echo "$ip <asset not match> $hostname"
   fi

done < $FILE

猜你喜欢

转载自blog.csdn.net/sinat_29173167/article/details/82784643
今日推荐