当前位置: 首页 > java >正文

Linux829 shell:expect interact “ “ set

问题

[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip=192.168.235.3
set pass=123456
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# chmod +x rsa.sh
[root@samba caozx26]# ./rsa.sh
can't read "ip=192.168.235.3": no such variablewhile executing
"set ip=192.168.235.3"(file "./rsa.sh" line 2)
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]#

在这里插入图片描述

[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password: [root@samba caozx26]# ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐

在这里插入图片描述

Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续

在这里插入图片描述

[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.sh
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3:cat ~/.ssh/id_rsa.sh
ssh: Could not resolve hostname 192.168.235.3:cat: Name or service not known
spawn_id: spawn id exp6 not openwhile executing
"interact"(file "./rsa.sh" line 11)

记录

    ┌───────────────────────────────────────────────────────────────────      ───┐│                 • MobaXterm Personal Edition v23.2 •                       ││               (SSH client, X server and network tools)                     ││                                                                            ││ ⮞ SSH session to code@192.168.235.10                                       ││   • Direct SSH      :  ✓                                                   ││   • SSH compression :  ✓                                                   ││   • SSH-browser     :  ✓                                                   ││   • X11-forwarding  :(remote display is forwarded through SSH      )  ││                                                                            ││ ⮞ For more info, ctrl+click on help or visit our website.                  │└───────────────────────────────────────────────────────────────────      ───┘Last login: Wed Aug 20 21:35:45 2025 from 192.168.235.1
[code@samba ~]$ sudo su
[sudo] code 的密码:
code 不在 sudoers 文件中。此事将被报告。
[code@samba ~]$ su - caozx26
密码:
上一次登录:日 817 10:55:56 CST 2025pts/4 上
[caozx26@samba ~]$ sudo su
[sudo] caozx26 的密码:
[root@samba caozx26]# yum install expect -y
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
local1                                                 | 3.6 kB     00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 expect.x86_64.0.5.45-14.el7_1 将被 安装
--> 正在处理依赖关系 libtcl8.5.so()(64bit),它被软件包 expect-5.45-14.el7_1.x86_64 需要
--> 正在检查事务
---> 软件包 tcl.x86_64.1.8.5.13-8.el7 将被 安装
--> 解决依赖关系完成依赖关系解决==============================================================================Package        架构           版本                      源              大小
==============================================================================
正在安装:expect         x86_64         5.45-14.el7_1             local1         262 k
为依赖而安装:tcl            x86_64         1:8.5.13-8.el7            local1         1.9 M事务概要
==============================================================================
安装  1 软件包 (+1 依赖软件包)总下载量:2.1 M
安装大小:4.9 M
Downloading packages:
------------------------------------------------------------------------------
总计                                             7.6 MB/s | 2.1 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装    : 1:tcl-8.5.13-8.el7.x86_64                                 1/2正在安装    : expect-5.45-14.el7_1.x86_64                               2/2验证中      : 1:tcl-8.5.13-8.el7.x86_64                                 1/2验证中      : expect-5.45-14.el7_1.x86_64                               2/2已安装:expect.x86_64 0:5.45-14.el7_1作为依赖被安装:tcl.x86_64 1:8.5.13-8.el7完毕!
[root@samba caozx26]# which exxpect
/usr/bin/which: no exxpect in (/sbin:/bin:/usr/sbin:/usr/bin)
[root@samba caozx26]# which expect
/bin/expect
[root@samba caozx26]# ssh root@192.168.235.3
The authenticity of host '192.168.235.3 (192.168.235.3)' can't be established.
ECDSA key fingerprint is SHA256:z4YsvU4MaDF8vJ2Z51wO5oAizA2QE2DNSqaae5BfBO0.
ECDSA key fingerprint is MD5:77:70:db:97:e6:0f:06:3f:23:40:9a:89:83:af:ac:ba.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
[root@samba caozx26]# ssh root@192.168.235.3
The authenticity of host '192.168.235.3 (192.168.235.3)' can't be established.
ECDSA key fingerprint is SHA256:z4YsvU4MaDF8vJ2Z51wO5oAizA2QE2DNSqaae5BfBO0.
ECDSA key fingerprint is MD5:77:70:db:97:e6:0f:06:3f:23:40:9a:89:83:af:ac:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.235.3' (ECDSA) to the list of known hosts.root@192.168.235.3's password:
Last login: Fri Aug 29 20:59:12 2025 from 192.168.235.1
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip=192.168.235.3
set pass=123456
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# chmod +x rsa.sh
[root@samba caozx26]# ./rsa.sh
can't read "ip=192.168.235.3": no such variablewhile executing
"set ip=192.168.235.3"(file "./rsa.sh" line 2)
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password: [root@samba caozx26]# ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 29 21:03:23 2025 from 192.168.235.10
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐
[root@samba caozx26]# ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 29 21:31:25 2025 from 192.168.235.10
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# exit
exit
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ vim rsa.sh/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: a: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
[caozx26@samba ~]$ ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ vim rsa.sh
[caozx26@samba ~]$ sudo su
[sudo] caozx26 的密码:
[root@samba caozx26]# ls
app         km  nntp.sh     ntp.sh     until.sh  模板  文档  桌面
find.sh     l2  ntp1.sh     rsa.sh     utilc.sh  视频  下载
inotify.sh  ll  ntpdate.sh  until1.sh  公共      图片  音乐
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.shexpect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3:cat ~/.ssh/id_rsa.sh
ssh: Could not resolve hostname 192.168.235.3:cat: Name or service not known
spawn_id: spawn id exp6 not openwhile executing
"interact"(file "./rsa.sh" line 11)
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.sh
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip "cat  ~/.ssh/id_rsa.sh"
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat  ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat  ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 29 21:44:22 2025 from 192.168.235.10
[root@nfs ~]# cd ~/.ssh
[root@nfs .ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@nfs .ssh]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat  ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip "cat  ~/.ssh/id_rsa.pub"
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat  ~/.ssh/id_rsa.pub
root@192.168.235.3's password:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDO0uF9+65Vnab1xc+GXvH/YqTXXfohWcTdFPtkbCzKjRez0bDAiOU9uVesqfEfQbjqcQFcwqIdR4MTSX9F+hu6dZkaHuPhDaXG7JCIa4N+8jpWPtOaY+nD0QHgRVheORIgKZvMv2/kYF6e8ihxo7FIUsYb5qT6+uZRWTnJAAc0x+EJSXIlwCaUVe9Pqdn7UECmO7gAlYZAcYz20iGgymz94IUfQIQtPEp1pbPquywFCpGcnEiA+pCNFuKqSC7sjbBWawWUdOwtAxlesD/hWRmYyqUGCVVQ+HYeBZHD1DlqFHCx7PDcViFO5tNbzxpC0q+jAC1O7vK5ueYU4xpI3xa1 root@nfs.cn
[root@samba caozx26]#
http://www.xdnf.cn/news/19204.html

相关文章:

  • 解密PCI Express:现代计算机的“高速公路“是如何设计的?
  • W25Q64的写入
  • stm32单片机使用tb6612驱动编码器电机并测速的驱动代码详解—详细参考开发手册(可移植+开发手册)
  • 【系列02】端侧AI:构建与部署高效的本地化AI模型 第1章:为什么是端侧AI?
  • 音乐云测试报告
  • 【笔记】扩散模型(一二)U-ViT|Diffusion with Transformer
  • 大模型应用01——火山方舟大模型服务平台快速入门
  • 端到端推荐大模型OneSug颠覆电商查询推荐!端到端生成式框架降延迟43%,长尾场景突破传统瓶颈
  • 订餐后台管理系统 - day04退出登录与账号管理模块
  • layout版图设计学习笔记3_linux基础指令
  • YOLO v11 目标检测+关键点检测 实战记录
  • 3.1 DataStream API 编程模型
  • 矿用随钻测量现场应用中,最新的MEMS陀螺定向短节的优势是什么?
  • 如何禁止网站内容被复制:技术、策略与深度思考
  • 智慧园区安防技术一站式解决方案-云迈智慧园区管理系统
  • Ansible 常用模块详解文档
  • 龙迅#LT7642GX适用于4路HDMI2.1/DP/TPYE-C转HDMI+LVDS/MIPI混合开关应用,分辨率高达8K30HZ !
  • 2025 年邮件服务器软件推荐:国产化与智能化并重的选型指南
  • 【SOD】目标检测
  • 《WINDOWS 环境下32位汇编语言程序设计》第8章 通用对话框
  • 【dtcc】数据库 随笔
  • Python字符串转日期完全指南:从基础到企业级应用实践
  • 第三方软件测试:【深度解析SQL注入攻击原理和防御原理】
  • 从自定义日期类角度解析运算符重载,友元函数(friend)
  • Java中使用Spring Boot+Ollama实现本地AI的MCP接入
  • Dify平台:Agent开发初学者指南
  • Mybatis的常用标签
  • 高精度惯性导航供应商价格解析
  • 【Java基础|第三十篇】File流
  • GitHub 宕机自救指南:打造韧性开发体系