前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >expect shell自动连接ssh服务器

expect shell自动连接ssh服务器

原创
作者头像
用户9955628
发布2022-09-09 09:43:26
1.3K0
发布2022-09-09 09:43:26
举报
文章被收录于专栏:python3基础算法
代码语言:javascript
复制
#!/usr/bin/expect

set PORT 2222
set HOST 13.214.147.196
set USER root
set PASSWORD DT8ajY0lFudf6D9Y


spawn ssh -p $PORT $USER@$HOST
expect {
        "yes/no" {send "yes\r";exp_continue;}
        "*password:*" {send "$PASSWORD\r"}
}
interact

将以上文件保存为 test_client

打开items,将文件位置填到command,前面加上expect+空格

expect脚本解读:

下载安装:

代码语言:javascript
复制
$ apt-get install expect
代码语言:javascript
复制
$ yum install expect

spawn

Starts a script or a program.

expect

Waits for program output.

send

Sends a reply to your program.

interact

Allows you to interact with your program.

  • The spawn command starts a script or a program like the shell, FTP, Telnet, SSH, SCP, and so on.
  • The send command sends a reply to a script or a program.
  • The Expect command waits for input.
  • The interact command allows you to define a predefined user interaction.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档