简体   繁体   English

将awk日志保存在尾部后的命令

[英]Command after saving awk log inside a tail

Sorry if the question is duplicated, it's that I'm new here and I'm learning to use this system. 抱歉,如果问题重复,那是我在这里是新手,并且我正在学习使用此系统。

I have the command below that saves in a log an ip that hit with the varialvel string. 我在下面的命令中将使用varialvel字符串命中的ip保存在日志中。

I wanted that after saving this ip in the log file would run the squid reconfiguration command, the "squid -k reconfigure" to reconfigure the squid and release the access based on that ip captured and thrown in the log. 我希望将这个IP保存在日志文件中之后,将运行squid reconfiguration命令,使用“ squid -k reconfigure”来重新配置squid,并根据在日志中捕获并抛出的IP释放访问权限。

Can someone help me? 有人能帮我吗?

#!/bin/sh

TAIL="/usr/bin/tail -f"
SQUID="/var/log/squid/access.log"
SQUID2="/usr/sbin/squid -k reconfigure"
PRINCIPAL2="http://cartilha.cert.br/"
LOG="/var/corples/pagina-inicial/autenticados.txt"

$TAIL $SQUID | gawk -v var2=$PRINCIPAL2 '{if ($7 == var2) {print $3} fflush()}' >> $LOG

Have you tried: 你有没有尝试过:

$TAIL $SQUID | gawk -v var2=$PRINCIPAL2 '{if ($7 == var2) {print $3; fflush(); system("/usr/sbin/squid -k reconfigure")}' >> $LOG

Please review How to 'grep' a continuous stream? 请查看如何“ grep”连续流? however. 然而。 Also consider what happens when the log gets rotated, if your system is configured to do this. 如果将系统配置为旋转日志,还请考虑旋转日志时会发生什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM