未找到生成命令 [英] Spawn command not found

查看:42
本文介绍了未找到生成命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试运行 .sh 文件时出错

<上一页>第 2 行:spawn:找不到命令: 无此文件或目录bash.sh:第 3 行:期望:找不到命令bash.sh:第 4 行:发送:找不到命令

#!/usr/bin/expect -fspawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX期待XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"发送我的密码"

知道为什么会这样吗?

解决方案

对我来说可以正常工作(来自 sftp 的错误:ssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not known),虽然 () 脚本有点令人反感 ;-)

当这种无法解释/不可预测的行为发生时,通常是因为脚本是在 (notepad.exe),它使用 来分隔行.这对 / 脚本,因为只需要 作为行分隔符.

您可以使用 dos2unixunix2dos 实用程序 在两种格式之间进行转换.作为一个实验,我将你的脚本转换为dos"格式,果然得到了类似的错误:

ubuntu@ubuntu:~$ unix2dos bash.shunix2dos:将文件 bash.sh 转换为 DOS 格式...ubuntu@ubuntu:~$ ./bash.sh: 无此文件或目录ubuntu@ubuntu:~$ dos2unix bash.shdos2unix:将文件 bash.sh 转换为 Unix 格式...ubuntu@ubuntu:~$ ./bash.shspawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXXssh:无法解析主机名 XXX.XXX.XXX.XXX:名称或服务未知无法读取数据包:对等方重置连接发送:spawn id exp6 未打开在执行时发送我的密码""(文件./bash.sh"第 4 行)ubuntu@ubuntu:~$

I have an error trying to run a .sh file

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"

Any idea why it happens?

解决方案

It works OK for me (error from sftp: ssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not known), though the .sh extension for an () script is a little off-putting ;-)

Often when this sort of unexplainable/unpredictable behavior happens, it is because the script was edited under (notepad.exe), which uses to delimit lines. This plays havoc with / scripts, as only is expected as a line delimiter.

You can use the dos2unix and unix2dos utilities to convert between the two formats. As an experiment, I converted your script to "dos" format, and sure enough got a similar error:

ubuntu@ubuntu:~$ unix2dos bash.sh 
unix2dos: converting file bash.sh to DOS format ...
ubuntu@ubuntu:~$ ./bash.sh 
": no such file or directory
ubuntu@ubuntu:~$ dos2unix bash.sh 
dos2unix: converting file bash.sh to Unix format ...
ubuntu@ubuntu:~$ ./bash.sh 
spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX
ssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not known
Couldn't read packet: Connection reset by peer
send: spawn id exp6 not open
    while executing
"send "myPassword""
    (file "./bash.sh" line 4)
ubuntu@ubuntu:~$ 

这篇关于未找到生成命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆