一、创建一个目录,用来存放脚本
[root@localhost scripts]# tree
.
├── host
└── ssh.sh
0 directories, 2 files
[root@localhost scripts]#
二、编写脚本
[root@localhost scripts]# cat ssh.sh
#!/bin/bash
set -e
yum -y install expect
if [ ! -f ~/.ssh/id_rsa ];then
ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
else
echo "id_rsa already exist "
fi
while read line
do
user=`echo $line | cut -d " " -f 2`
ip