原生的bash 无法完成此操作,需要借助expect 来完成操作
1 安装expject
yum install -y expect
2 编写脚本
我这里实现了自动登录 然后调用pwd命令
#!/usr/bin/expect
spawn ssh root@192.168.1.133
expect "*password*" {send "password\r"}
expect "]*" {send "pwd \r"}
interact
原生的bash 无法完成此操作,需要借助expect 来完成操作
1 安装expject
yum install -y expect
2 编写脚本
我这里实现了自动登录 然后调用pwd命令
#!/usr/bin/expect
spawn ssh root@192.168.1.133
expect "*password*" {send "password\r"}
expect "]*" {send "pwd \r"}
interact