问题描述
我有一个错误尝试运行sh文件
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 [email protected]
expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':"
send "myPassword"
任何想法,为什么会发生?
Any idea why it happens?
推荐答案
它的工作原理OK,我(从错误SFTP: SSH:无法解析主机名XXX.XXX.XXX.XXX:姓名或服务不知道
),尽管 .SH
扩展的的(的)脚本是有点倒胃口; - )
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 expect (tcl) script is a little off-putting ;-)
通常,当这种莫名/ UN predictable行为发生,这是因为剧本是根据的(记事本),它使用 \\ r \\ n
划线。这起严重破坏 /的脚本,因为只有 \\ n
有望作为行分隔符。
Often when this sort of unexplainable/unpredictable behavior happens, it is because the script was edited under windows (notepad.exe), which uses \r\n
to delimit lines. This plays havoc with unix/linux scripts, as only \n
is expected as a line delimiter.
您可以使用以这两种格式之间进行转换。作为一个实验,我转换你的脚本为DOS格式,果然得到了类似的错误:
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 [email protected]
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:~$
这篇关于产卵命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!