[英]shell script wget not working when used as a cron job
i have a function in a php web app that needs to get periodically called by a cron job. 我在php Web应用程序中有一个功能,需要由cron作业定期调用。 originally i just did a simple wget to the url to call the function and everything worked fine, but ever since we added user auth i am having trouble getting it to work. 最初,我只是对URL进行了简单的wget调用该函数,并且一切正常,但是自从我们添加了用户身份验证以来,我一直无法使其正常工作。
if i manually execute these commands i can login, get the cookie and then access the correct url: 如果我手动执行这些命令,我可以登录,获取Cookie,然后访问正确的URL:
site=http://some.site/login/in/here
cookie=`wget --post-data 'username=testuser&password=testpassword' $site -q -S -O /dev/null 2>&1 | awk '/Set-Cookie/{print $2}' | awk 'NR==2{print}'`
wget -O /dev/null --header="Cookie: $cookie" http://some.site/call/this/function
but when executed as a script, either manually or through cron, it doesn't work. 但是当作为脚本执行时,无论是手动执行还是通过cron执行,都无法正常工作。
i am new to shell scripting, any help would be appreciated 我是shell脚本的新手,将不胜感激
this is being run on ubuntu server 10.04 这正在ubuntu服务器10.04上运行
In theory, the only difference from manually executing these and using a script would be the timing. 从理论上讲,与手动执行这些脚本和使用脚本的唯一区别是时间安排。
Try inserting a sleep 5
or so before the last command. 尝试在最后一个命令之前插入sleep 5
左右。 Maybe the http server does some internal communication and that takes a while. 也许http服务器进行了一些内部通信,这需要一段时间。 Hard to say, because you didn't post the error you get. 很难说,因为您没有发布错误。
OK simple things first - 首先确定简单的事情-
#!/bin/bash
or something 我认为文件以#!/bin/bash
开头 chmod
ded the file +x
您已将文件+x
chmod
0x0d
line endings 您正在使用Unix 0x0d
行尾 And you're not expecting to return any of the variables to the calling shell, I presume? 我想您不希望将任何变量返回给调用shell。
Failing this try tee
ing the output of each command to a log file. 如果做不到这一点尝试tee
荷兰国际集团的每个命令的输出到一个日志文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.