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

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.dtcms.com/a/357099.html

相关文章:

  • 知识卡片html5动态网页源码
  • CRYPT32!CryptMsgUpdate函数分析之CRYPT32!PkiAsn1Decode函数的作用是得到pci
  • ros2--topic/话题--接口
  • tauri打包失败
  • 太阳光模拟器在卫星研发与测试中的应用
  • wav音频转C语言样点数组
  • 嵌入式Linux设备树驱动开发 - dtsof驱动
  • shell学习(二)
  • Sharding-JDBC 使用方法
  • 为什么不能创建泛型数组?
  • C++并发编程-17. 线程安全的链表
  • Unity EventTrigger 动态添加事件
  • flume事务机制详解:保障数据可靠性的核心逻辑
  • 项目中为什么使用SpringBoot?
  • 晨控CK-FR102ANS与欧姆龙NX系列PLC配置EtherNet/IP通讯连接手册
  • 如何规划一年、三年、五年的IP发展路线图?
  • Android 端 QGroundControl 控制 PC 端Gazebo Sim 仿真无人机
  • 龙迅#LT7642GX适用于4路HDMI2.1/DP/TPYE-C转HDMI+LVDS/MIPI混合开关应用,分辨率高达8K30HZ !
  • ADFS 和 OAuth 的区别
  • 第三届机械工程与先进制造智能化技术研讨会(MEAMIT2025)
  • 打造企业内部的“技术桥梁”:超级用户机制如何助力制造企业高效运维
  • “聚势同行・创赢未来”淮南高新区科技型企业沙龙——2025大数据企业专场成功举办
  • 解决RTX3070魔改16G在UBUNTU中黑屏问题
  • AI模型库哪个好?2025年主流AI模型选型指南与API成本对比推荐
  • 在现场把“数据”变成可用的力量 —— 谈EG8200Lite的实战价值
  • 七牛云灵矽AI实践:构建可扩展智能体的开放协议与架构
  • C++实现快速反转一个数的算法
  • “上门做饭”平台的核心技术栈与运营壁垒是什么?
  • linux系统学习(13.系统管理)
  • 【混合开发】Android+webview模拟crash崩溃补充说明