我想要一个bash脚本,控制cron
每天都跑,我想grep从python
(Django)输出的一些行并发布它与slacktee我的闲暇频道。但我只是从脚本中捕捉一些警告,而不是我自己的打印(与std :: out和std :: err有关)?但我似乎无法调试它。Cronned Django命令输出没有张贴在三通从bash脚本
#!/bin/bash
printf "\nStarting the products update command\n"
DATE=`date +%Y-%m-%d`
source mypath/bin/activate
cd some/path/_production/_server
./manage.py nn_products_update > logs/product_updates.log
tail --lines=1000 logs/product_updates.log | grep INFO | grep $DATE
所以每一天,我试图给grep这样的消息:
[INFO][NEURAL_RECO_UPDATE][2017-08-28 22:15:04] Products update...
但它不会印在T形通道。此外,该文件每天都会被覆盖,而不是附加 - 请问如何更改该文件?当在shell中自行运行时,tail
命令可以正常工作。这怎么可能? (抱歉问两个,但我相信他们是某种相关的,只是不能找到答案)
这是万一cron
条目。
20 20 * * * /bin/bash /path/to/server/_production/bin/runReco.sh 2>&1 | slacktee.sh -c 'my_watch'
非常感谢
编辑:
输出使用grep -e INFO -e $DATE
grep: [INFO][NEURAL_RECO_UPDATE][2017-08-29: No such file or directory
grep: 07:36:56]: No such file or directory
grep: No: No such file or directory
grep: new: No such file or directory
grep: active: No such file or directory
grep: products: No such file or directory
grep: to: No such file or directory
grep: calculate.: No such file or directory
grep: Terminating...: No such file or directory
嗨!感谢你的回答。它有点作品,但是当我按照你的建议使用TMPFILE和grep -e时,如果打印出像我在上面的问题中编辑过的东西。大多数情况下,问题出现在'>'vs'>>'中,现在它可以工作,但'DATE'的grep不起作用,整个带INFO文件被打印出来。 :( –
确实:'grep -e INFO -e $ DATE logs/product_updates.log'生成正确的输出?'$ TMPFILE'的输出可能需要grep的'--line-buffered'选项 – fcbsd
它现在只需用'>>'修复就行了!非常感谢! –