#!/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
备份地址: 【while 读文件一行问题】