实现ssh 自动登录 Posted on 2018-05-30 Edited on 2024-05-21 (expect 可能需要安装) 12345678910111213141516171819#!/usr/bin/expectset timeout 60set host ***.**.**.***set name rootset password 123456spawn ssh $host -l $nameexpect { "(yes/no)?" { send "yes\n" expect "password:" send "$password\n" } "password:" { send "$password\n" }}interact **PS: ** spawn命令:spawn是进入expect环境后才可以执行的expect内部命令。 interact:执行完成后保持交互状态,把控制权交给控制台,这个时候就可以手工操作了。 实现git自动pull(http)12345678910#!/usr/bin/expect -fset uname pandaomengset password 123456set timeout 3cd /home/workspaces/vue-demo #项目路径spawn git pull origin devexpect "*Username*" {send "$uname\r"; exp_continue}expect "*Password*" {send "$password\r"}interact