为了方便使用,将脚本进行整合,整合后的脚本如下:
[root@h3c kewai]# cat plgm.sh
#!/bin/bash`
ssh-keygen -t rsa -P '' -f '/root/.ssh/id_rsa'
for i in $(awk '{print $1}' /root/ip.txt)
do
ip=$(awk -v IP="$i" '{if(IP==$1) print $1}' /root/ip.txt|awk -F"," '{print $1}')
name=$(awk -v IP="$i" '{if(IP==$1) print $1}' /root/ip.txt | awk -F"," '{print $2}')
echo "name=$name"
echo $ip
expect ssh-copy-id-batch.exp $ip
expect modify-server-name.exp $ip $name
expect modify-server-name.2.exp $ip $name
done
说明:expect脚本与shell脚本最好放在同一个目录下(×××部分)!如下: