bash - 找不到生成命令

标签 bash shell command expect spawn

我在尝试运行 .sh 文件时遇到错误

line 2: spawn: command not found
": no such file or directory
bash.sh: line 3: expect: command not found
bash.sh: line 4: send: command not found
#!/usr/bin/expect -f
spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX
expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"
send "myPassword"

知道为什么会这样吗?

最佳答案

  1. 这是一个 expect 脚本,所以“.exp”将是一个合适的文件扩展名:mv bash.sh sftp.exp
  2. 不要像 bash bash.shsh bash.sh 那样启动它。做这个:
    1. 使程序可执行:chmod a+x sftp.exp
    2. 使用 ./sftp.exp/path/to/sftp.exp 启动它,或者将它移动到 $PATH 中的目录并使用 sftp.exp
  3. 在您发送“myPassword”之后,您必须“按回车键”:send "myPassword\r"
  4. 在开发 expect 程序时,将 exp_internal 1 添加到顶部。

祝你好运,再回来提出更多问题。

关于bash - 找不到生成命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21151042/

相关文章:

wpf - 命令绑定(bind)到 ContextMenu(在 ListBox 中的 ListBoxItem 上)不起作用

php - PHP中的SSH连接和命令

linux - 用于编译和运行 C++ 程序的 Bash 脚本

linux - Bash:文本格式

bash——基于特定列的两个文件的交集?

linux - 使用文件计数列出文件夹的 UNIX 命令

bash - 为进程分配 cpu 核心 - Linux

python - eclipse中使用django环境的shell,pydev给出语法错误

perl - 在 perl 脚本中使用环境变量

bash 脚本 : to check if Apache server is up and running