expect 真是一个好东西,可以解决免密登录服务器和免密下载的问题。
记录一下。
免密登录:from here
mac 安装brew /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install mac安装expect(需要先安装brew,没有安装的话看上边) brew install expect mac一键登录服务器脚本 set user "username" set host "123.126.88.**" set password "yourpassword" set timeout -1 spawn ssh $user@$host expect "*assword:*" send "$password\r" interact # expect eof
另一个例子是这里:
[root@localhost ~]# vim auto_login.sh #!/usr/bin/expect spawn ssh [email protected] expect { “(yes/no)” {send “yes\r”; exp_continue} “*password” {send “123123\r”} } interact
免密拷贝:
cat /opt/shell/expect_scp.sh #!/bin/bash ip="10.168.1.202" user="root" expect << EOF set timeout -1 spawn bash -c “scp -pr /home/* $user@$ip:/home/” expect { “yes/no” {send “yes\r”;exp_continue} “password” {send_user "come here"; send “123456\r”;} } expect eof exit EOF
标签:bin,shell,set,登录,send,之免,免密,expect From: https://www.cnblogs.com/snake553/p/17244307.html