简体   繁体   English

Wget在bash脚本中有406不可接受的错误

[英]Wget in bash script with 406 Not Acceptable Error

On my Centos 6.2 I have this bash script: 在我的Centos 6.2上,我有这个bash脚本:

[le_me]$ cat get.nb
#! /bin/bash
/usr/bin/wget -O /var/www/html/leFile.xml http://www.leSite.com/leFeed.xml    

[le_me]$ source getFeeds.nb
: command not found
--2012-06-22 12:46:18--  http://www.leSite.com/leFeed.xml%0D
Resolving www.leSite.com... 1.2.3.4
Connecting to www.leSite.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 406 Not Acceptable
2012-06-22 12:46:18 ERROR 406: Not Acceptable.

The strange thing for me is that when I run this command 对我来说奇怪的是,当我运行这个命令时

/usr/bin/wget -O /var/www/html/leFile.xml http://www.leSite.com/leFeed.xml

in the console, everything works fine and the file is downloaded without a problem. 在控制台中,一切正常,文件下载没有问题。

I did google about it and I noticed this %0D which supposed to be a carrige return character, and I tried putting another space after the link like so: http://www.leSite.com/leFeed.xml[spaceChar] 我做了谷歌关于它,我注意到这个%0D应该是一个carrige返回字符,我尝试在链接之后添加另一个空格如下: http://www.leSite.com/leFeed.xml[spaceChar]http://www.leSite.com/leFeed.xml[spaceChar] spaceChar http://www.leSite.com/leFeed.xml[spaceChar]

and I got the file downloaded but I'm concerned about the command not found output and fetching that carrige return in the end (which ofc I know it's because of the space, but now at least I downloaded the file I originally wanted): 我得到了文件下载,但我担心命令未找到输出并最终获取carrige返回(我知道这是因为空间,但现在至少我下载了我原来想要的文件):

[le_me]$ source get.nb
: command not found
--2012-06-22 13:05:26--  http://www.leSite.com/leFeed.xml
Resolving www.leSite.com... 2.17.249.51
Connecting to www.leSite.com|2.17.249.51|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 35671435 (34M) [application/atom+xml]
Saving to: “/var/www/html/leFile.xml”

100%[=================================>] 35,671,435  37.2M/s   in 0.9s

2012-06-22 13:05:27 (37.2 MB/s) - “/var/www/html/leFile.xml” saved [35671435/35671435]

--2012-06-22 13:05:27--  http://%0D/
Resolving \r... failed: Name or service not known.
wget: unable to resolve host address “\r”
FINISHED --2012-06-22 13:05:27--
Downloaded: 1 files, 34M in 0.9s (37.2 MB/s)

Can anyone shed some light on this please? 有人可以对此有所了解吗?

Your script file apparently has DOS-style lines, and the carriage return character is interpreted as just another character in the command line. 您的脚本文件显然具有DOS样式的行,并且回车符被解释为命令行中的另一个字符。 If you have no space after the URL, it is interpreted as the last character of the URL; 如果URL后面没有空格,则将其解释为URL的最后一个字符; if you have a space, it is interpreted as a separate one-character parameter. 如果您有空格,则将其解释为单独的单字符参数。

You should save your script file with UNIX-style lines. 您应该使用UNIX样式的行保存脚本文件。 How you do that depends on your editor. 你如何做到这一点取决于你的编辑。

我建议引用网址。

/usr/bin/wget -O /var/www/html/leFile.xml 'http://www.leSite.com/leFeed.xml'

The

: command not found

error suggests there is a problem in http:// part. 错误表明http://部分存在问题。 As a rule of thumb I always quote those urls when using in command line. 根据经验,我总是在命令行中使用时引用这些URL。 You often have bash/shell special characters in there. 你经常有bash / shell特殊字符。

In my case this command works for me without 406 problem (with some real http address). 在我的情况下,这个命令适用于我没有406问题(有一些真正的http地址)。 You should copy/paste the exact address. 您应该复制/粘贴确切的地址。 It probably contains something that causes it. 它可能包含导致它的东西。

如果其他答案都不起作用,请尝试替代wget

curl -o /var/www/html/leFile.xml 'http://www.leSite.com/leFeed.xml'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM