我在尝试运行 .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"
知道为什么会这样吗?
最佳答案
- 这是一个 expect 脚本,所以“.exp”将是一个合适的文件扩展名:
mv bash.sh sftp.exp
- 不要像
bash bash.sh
或sh bash.sh
那样启动它。做这个:- 使程序可执行:
chmod a+x sftp.exp
- 使用
./sftp.exp
或/path/to/sftp.exp
启动它,或者将它移动到 $PATH 中的目录并使用sftp.exp
- 使程序可执行:
- 在您
发送“myPassword”
之后,您必须“按回车键”:send "myPassword\r"
- 在开发 expect 程序时,将
exp_internal 1
添加到顶部。
祝你好运,再回来提出更多问题。
关于bash - 找不到生成命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21151042/