I have controller node (CN) and server nodes (SN). From CN, I need to config the hostname of each and every SN. inv file contains list of SNs and corresponding hostname.
In below script, I am not sure how to pass hostname variable. Any best way to achieve same?
#!/bin/bash
IFS='\n'
for data in `awk 'NR>1 {print}' inv`
do
ip=`awk '{print $1}' <<< $data`
hostname=`awk '{print $2}' <<< $data`
ssh root@$ip "hostnamectl set-hostname $hostname"
done
inv file,
IPs Hostname
172.31.98.11 Server1
172.31.106.177 Server2
172.31.97.105 Server3
hostnamectlon the server should already be called with the correct value (the variable is expanded before the string is sent the server. Does the variable contain the correct value?