发布网友 发布时间:2022-04-23 16:48
共1个回答
热心网友 时间:2023-10-09 18:06
#!/bin/bash
passwd="yourpasswd"
while read ip servername
do
expect << EOF
spawn ssh -l root $ip
expect {
"yes/no" { send "yes\r";exp_continue }
"password:" { send "$passwd\r" }
}
expect "#"
send "sed -i '/HOSTNAME/d' /etc/sysconfig/network \r"
expect "#"
send "echo 'HOSTNAME=$servername' >> /etc/sysconfig/network \r"
expect "#"
send "hostname $servername \r"
expect "#"
send "exit \r"
EOF
done < host.list
host.list 内容: IP 要修改的主机名