Re: 为何命令行上正确执行的命令,放在crontab里就不能正确运行?
Zhang Weiwu wrote:
> 命令行表现:
>
> $ bin/taobao_report.sh "http://search1.taobao.com/browse/34-50008266-50008232/n-4----------------------0----------------g,gi4tsobrhi4dinbxha--g,gi4tsobrhlfpvr6z-----g,y7mq-------1---------40--coefp-0-all-50008232.htm?ssid=s5#ListView" 二手人气500元以上竖琴
> Received cookie: uc1=cookie14=UoM%2F0dGt7L%2FGEA%3D%3D
> Received cookie: cookie2=d416443cb27990e6dd8560a23b002ac5
> Received cookie: uc1=cookie14=UoM%2F0dGt7L%2FGEA%3D%3D
> Received cookie: cookie2=40e525226327b95ba1aa685858dc2ede
>
> 结果:我的电子邮箱里收到一封信,标题是淘宝上此物的数量,内容是物品描述。
>
> 放在crontab里:
> $ crontab -l
> # m h dom mon dow command
> 03 16 * * * /usr/bin/w3m -dump "http://search1.taobao.com/browse/34-50008266-50008232/n-4----------------------0----------------g,gi4tsobrhi4dinbxha--g,gi4tsobrhlfpvr6z-----g,y7mq-------1---------40--coefp-0-all-50008232.htm?ssid=s5#ListView" | /bin/grep -A 100 对比 | /usr/bin/mail -a 'Content-Type: text/plain; charset=UTF-8' -s '=?UTF-8?B?'`/usr/bin/w3m -dump http://search1.taobao.com/browse/34-50008266-50008232/n-4----------------------0----------------g,gi4tsobrhi4dinbxha--g,gi4tsobrhlfpvr6z-----g,y7mq-------1---------40--coefp-0-all-50008232.htm?ssid=s5#ListView | grep 找到.*件 | base64 -w0`'?=' zhangweiwu@realss.com
>
>
上述长命令,即使放在脚本里也是同样不能用于crontab。
脚本:
$ cat bin/taobao_report_full.sh
#!/bin/sh
/usr/bin/w3m -dump http://search1.taobao.com/browse/34-50008266-50008232/n-4----------------------0----------------g,gi4tsobrhi4dinbxha--g,gi4tsobrhlfpvr6z-----g,y7mq-------1---------40--coefp-0-all-50008232.htm?ssid=s5#ListView | /bin/grep -A 100 对比 | /usr/bin/mail -a 'Content-Type: text/plain; charset=UTF-8' -s '=?UTF-8?B?'`/usr/bin/w3m -dump http://search1.taobao.com/browse/34-50008266-50008232/n-4----------------------0----------------g,gi4tsobrhi4dinbxha--g,gi4tsobrhlfpvr6z-----g,y7mq-------1---------40--coefp-0-all-50008232.htm?ssid=s5#ListView | grep 找到.*件 | base64 -w0`'?=' zhangweiwu@realss.com
You have new mail in /var/mail/zhangweiwu
此脚本在命令行调用正常:
$ bin/taobao_report_full.sh
Received cookie: uc1=cookie14=UoM%2F0dGt7hbQYQ%3D%3D
Received cookie: cookie2=336c825164a9cc509d24f3234a84de89
Received cookie: uc1=cookie14=UoM%2F0dGt7hbQYQ%3D%3D
Received cookie: cookie2=553eb2d684cdfe65a22aee2d742df16a
而在crontab里调用会产生空白信件:
$ crontab -l
# m h dom mon dow command
46 16 * * * bin/taobao_report_full.sh
Reply to: