Linux期待脚本

时间:2015-10-23 14:01:03

标签: expect

我花了8个小时的时间试图用谷歌来解决这个问题,所以我希望这可以在这里询问。

当我尝试从vmware中的lubuntu映像连接到由usb连接的物理设备时,我需要一个自动输入密码的脚本。

我已经尝试了至少50种我在网上找到的不同脚本,但它们都没有工作(甚至可以识别产生命令)

这是我的剧本:

#!/usr/expect

spawn CPY2T_old.sh  
expect  "root@10.9.8.2's password:"   
send "ThePassword"
expect eof

CPY2T_old.sh的内容是

#!/bin/bash

cd hellolinux/src/Exercise$1 
scp $2 root@10.9.8.2:

上面的bash脚本运行正常,但我必须输入密码,这是我首先想要避免的。当我在cmd中执行时,expect脚本给出以下内容:

spawn: command not found
couldn't read file "root@10.9.8.2's password:": no such file or directory

The program 'send' can be found in the following packages:
 * mailutils-mh
 * nmh
Try: sudo apt-get install <selected package>
couldn't read file "eof": no such file or directory

我现在已经下载了mailutils和nmh至少十几次。在其他地方,我读到我需要在顶部关闭@echo,但是此命令无法识别并出错。

编辑:我无法对此设备执行无密码ssh,因此请不要建议。

1 个答案:

答案 0 :(得分:0)

我看到2个错误:第一个

#!/usr/expect

你想要

#!/usr/bin/expect

这应该会导致错误:你是如何启动预期脚本的?

第二

send "ThePassword"

你忘了按回车

send "ThePassword\r"