实现ssh 自动登录

(expect 可能需要安装)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/expect

set timeout 60
set host ***.**.**.***
set name root
set password 123456

spawn ssh $host -l $name
expect {
"(yes/no)?" {
send "yes\n"
expect "password:"
send "$password\n"
}
"password:" {
send "$password\n"
}
}
interact

**PS: **

  • spawn命令:spawn是进入expect环境后才可以执行的expect内部命令。
  • interact:执行完成后保持交互状态,把控制权交给控制台,这个时候就可以手工操作了。

实现git自动pull(http)

1
2
3
4
5
6
7
8
9
10
#!/usr/bin/expect -f
set uname pandaomeng
set password 123456
set timeout 3

cd /home/workspaces/vue-demo #项目路径
spawn git pull origin dev
expect "*Username*" {send "$uname\r"; exp_continue}
expect "*Password*" {send "$password\r"}
interact