[英]Cron Pipe zcat on Bash Script not working
I created a script based on the tutorial on this page: https://johnveldboom.com/posts/goaccess-automated-reports-last-30-days-via-cron/ .我根据此页面上的教程创建了一个脚本: https://johnveldboom.com/posts/goaccess-automated-reports-last-30-days-via-cron/ 。 When the script is run from the terminal it works perfectly.
当脚本从终端运行时,它可以完美运行。 The problem is when cron runs the script, pipe does not seem to work.
问题是当 cron 运行脚本时,pipe 似乎不起作用。
I Googled for possible solutions.我用谷歌搜索了可能的解决方案。 I tried adding "-c" to the bash on cron but that did not help.
我尝试将“-c”添加到 cron 上的 bash,但这没有帮助。
This is the Script这是脚本
#!/bin/bash
# filename: goaccess.sh (with +x permission)
HOST="myHost"
GOACCESSREPORT_DIR=/home/user/goaccess_reports/
DATE=$(date +'%Y.%m')
/bin/zcat `find /var/log/nginx/ -name "myhost_access.log.*.gz" -mtime -20` | goaccess > $GOACCESSREPORT_DIR/$HOST-monthly-$DATE.html
echo "My Host GoAccess Report" | sudo mail -s "My Host GoAccess Report" email@test.com -A $GOACCESSREPORT_DIR/$HOST-monthly-$DATE.html
This is my cron这是我的计划
00 22 * * 5 /bin/bash -c /home/user/goaccess.sh
The output file information is below, which lets me to think that piping is not working: output 文件信息如下,这让我认为管道不起作用:
GoAccess - 1.2 Usage: goaccess [filename] [ options... ] [-c][-M][-H][-q][-d][...] The following options can also be supplied to the command: Log & Date Format Options --date-format= - Specify log date format. GoAccess - 1.2 用法:goaccess [filename] [options...] [-c][-M][-H][-q][-d][...] 以下选项也可以提供给命令: 日志和日期格式选项 --date-format= - 指定日志日期格式。 eg, %d/%b/%Y --log-format= - Specify log format.
例如,%d/%b/%Y --log-format= - 指定日志格式。 Inner quotes need to be escaped, or use single quotes.
内引号需要转义,或者使用单引号。 --time-format= - Specify log time format.
--time-format= - 指定日志时间格式。 eg, %H:%M:%S User Interface Options -c --config-dialog - Prompt log/date/time configuration window. -i --hl-header - Color highlight active panel.
例如,%H:%M:%S 用户界面选项 -c --config-dialog - 提示日志/日期/时间配置 window。 -i --hl-header - 颜色突出显示活动面板。 -m --with-mouse - Enable mouse support on main dashboard.
-m --with-mouse - 在主仪表板上启用鼠标支持。 --color= - Specify custom colors. See manpage for more details and options.
--color= - 指定自定义 colors。有关更多详细信息和选项,请参见联机帮助页。 --color-scheme=<1|2|3> - Schemes: 1 => Grey, 2 => Green, 3 => Monokai.
--color-scheme=<1|2|3> - 方案:1 => 灰色,2 => 绿色,3 => Monokai。 --html-custom-css= - Specify a custom CSS file in the HTML report.
--html-custom-css= - 在 HTML 报告中指定自定义 CSS 文件。 --html-custom-js= - Specify a custom JS file in the HTML report.
--html-custom-js= - 在 HTML 报告中指定自定义 JS 文件。 --html-prefs= - Set default HTML report preferences.
--html-prefs= - 设置默认的 HTML 报告首选项。 --html-report-title=
--html-报告标题=
Thank you in advance.先感谢您。
I had the same problem and found the answer here .我遇到了同样的问题,在这里找到了答案。
You need to use a dash after the goaccess
command to tell it you are piping the logs in:您需要在
goaccess
命令之后使用破折号来告诉它您正在通过管道输入日志:
/bin/zcat `find /var/log/nginx/ -name "myhost_access.log.*.gz" -mtime -20` | goaccess - > $GOACCESSREPORT_DIR/$HOST-monthly-$DATE.html
This helped me also, thank you all.这对我也有帮助,谢谢大家。
I found that this worked best for me:我发现这对我最有效:
#!/bin/bash
# create the report
/usr/bin/zcat -f /var/log/nginx/nhh-access.* | /home/linuxbrew/.linuxbrew/bin/goaccess - --log-format=COMBINED > /var/www/logs/nhh.html
/usr/bin/zcat -f /var/log/nginx/no-host-access.* | /home/linuxbrew/.linuxbrew/bin/goaccess - --log-format=COMBINED > /var/www/logs/no-host.html
# change the title:
/usr/bin/sed -i 's/Server\ /nhh\ /' /var/www/logs/nhh.html
/usr/bin/sed -i 's/Server\ /no-host\ /' /var/www/logs/no-host.html
cron:计划:
# every 13 minutes:
*/13 * * * * /var/www/logs/goaccess-job.sh > /var/www/logs/go.log 2>&1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.