/*****shell_start*******/
#!/usr/bin/expect
set timeout 30
spawn ssh -p 3333 root@39.12.1.120 # 端口密码写自己的
expect "*password*" {send "123456\r"}
expect "*Welcome to Alibaba Cloud Elastic Compute Service !*"
send "su root\r"
expect "*密码*" {send "123456\r"}
interact
/*****shell_end*******/
expect 组件默认没有安装手动安装就好,命令如下:
yum intall expect (Centos 系统)
brew intall expect (Mac系统) 等。
脚本记得赋予可执行权限,sudo chmod +x ssh_test.sh
./ssh_test.sh 自动登录完成。