Quick SSH Landing
spot
- 账号密码真忘记了。wiki密密麻麻地不想看。
- 登陆的命令真不记得了
- 登陆好复杂,要输入两次密码。也没公钥登陆方法
preparation
how to use
相关文件
测试环境:
#!/usr/bin/expect
set PORT ****
set HOST *****
set USER root
set PASSWORD *********
send "开始连接远程服务器\n"
spawn ssh -p $PORT $USER@$HOST
expect {
"yes/no" {send "yes\r";exp_continue;}
"*password:*" {
send "$PASSWORD\r"
}
}
expect "Welcome"
send "gotolog convenient-test\r"
expect "*password*"
send "$PASSWORD\r"
expect "Welcome"
send "cd /data/logs\r"
send "ls -al\r"
interact
uat环境:
#!/usr/bin/expect
set PORT ****
set HOST ********
set USER *****
set PASSWORD *********
# uat 不能用这个001的case
set CASE1 001
set CASE2 002
set CASE3 003
set CASE4 004
set CASE5 005
set CASE6 006
set CASE7 007
set CASE8 008
set CASE9 009
send "开始连接远程服务器\n"
spawn ssh -p $PORT $USER@$HOST
expect {
"yes/no" {send "yes\r";exp_continue;}
"*password:*" {
send "$PASSWORD\r"
}
}
expect "Welcome"
send "gotolog convenient-uat\r"
expect {
"$CASE3" {send "ssh root@cn-test-003\r"}
"$CASE2" {send "ssh root@cn-test-002\r"}
"$CASE4" {send "ssh root@cn-test-004\r"}
"$CASE5" {send "ssh root@cn-test-005\r"}
"$CASE6" {send "ssh root@cn-test-006\r"}
"$CASE7" {send "ssh root@cn-test-007\r"}
"$CASE8" {send "ssh root@cn-test-008\r"}
"$CASE9" {send "ssh root@cn-test-009\r"}
}
expect "*password*"
send "$PASSWORD\r"
expect "Welcome"
send "cd /data/logs\r"
send "ls -al\r"
interact
design sketch




Reference document
最佳实践
liunx expect详解
更多应用的设想 和 未来展望
外部参数
difficulty
- stable环境要VPN,但是现在VPN又不给。
- 万一密码改了,我难道还要改sh么?能不能将配置弄到git上面,支持外部修改?
网友评论