【发布时间】:2018-02-06 06:22:57
【问题描述】:
我正在尝试每天运行一个由 cron 控制的 bash 脚本,我想从 python (Django) 输出中提取一些行并将其与 slacktee 一起发布到我的 slack渠道。但我只是从脚本中捕捉到一些警告,而不是我自己的打印(与 std::out 和 std::err 有关)?但我似乎无法调试它。
#!/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...
但它不会在 tee 通道中打印出来。此外,该文件每天都会被覆盖而不是附加 - 请问如何更改它? tail 命令在 shell 中单独运行时可以正常工作。这怎么可能? (抱歉问了两个,但我相信它们有某种相关性,只是找不到答案)
这是以防万一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
【问题讨论】: