ssh自动输入密码登陆

1  vi rm.sh

#!/bin/expect -f
set DATE [exec date +%Y%m%d%k]
set ipaddress [lindex $argv 0]
set port  [lindex $argv 1]
set logname [lindex $argv 2]
#set password xukeqiang
set date [exec date -d "-2 day" "+%Y%m%d"]
set fd [open /home/admin/passwd.sh r]
set password [read $fd]
close $fd
spawn ssh $ipaddress -p $port -l monitor
#set timeout 300
expect "monitor@${ipaddress}'s password:"
#set timeout 300
send "$password\r"
expect -re "\](\$|#)"
#send "rm -rf /tmp/${logname}${date}.tar\r"
send "sh /tmp/rm.sh\r"
expect -re "\](\$|#)"
send "exit\r"
expect eof

 2  vi ip.sh##此文件不能有多余的空行

192.168.1.101 22 nagiosa_

192.168.1.102 22 nagiosb_

192.168.1.103 22 nagiosc_

 

3  vi piliang.sh

#/bin/bash
time=`date +%Y%m%d_%H%M%S`
filename=/home/admin/ip.sh
while read line
do
        echo $line
        /bin/expect -f /home/admin/rm.sh $line
done<$filename |tee /home/admin/log.log$time
echo "run over" >>/home/admin/log.log$time 

 

4  将C:\cygwin64\bin追加到windows系统环境变量Path中,然后编辑批处理文件piliang.bat如下:

sh c:\cygwin64\home\admin\piliang.sh 
\cygwin64\bin\echo  ok

pause












本文转自shangshanyang51CTO博客,原文链接: http://blog.51cto.com/qqran/1905305,如需转载请自行联系原作者




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值