sshpass连接主机以及执行命令
[root@centos pb]# cat ssh.sh #!/bin/bash function Install_sshpass(){ sshpass -V > /dev/null 2&>1 if [ $? -ne 0 ] then yum -y install wget wget http://downloads.sourceforge.net/project/sshpass/sshpass/1.06/sshpass-1.06.tar.gz tar -xf sshpass-1.06.tar.gz cd sshpass-1.06 ./configure --prefix=/usr/local/sshpass make && make install cp -a /usr/local/sshpass/bin/sshpass /usr/bin/ fi } Install_sshpass ip=10.2.5.$1 pass="123456" sshpass -p "$pass" ssh root@$ip -o StrictHostKeyChecking=no $2 #sshpass -p "$pass" ssh root@$ip $2