我有一个错误尝试运行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 500200243@XXX.XXX.XXX.XXX 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 扩展的的预计(的 TCL )脚本是有点倒胃口; - )
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 划线。这起严重破坏 UNIX /的的Linux 脚本,因为只有 \\ 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.
您可以使用的 DOS2UNIX的和 unix2dos 公用事业以这两种格式之间进行转换。作为一个实验,我转换你的脚本为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 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:~$更多推荐
产卵命令未找到
发布评论