0

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.

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.

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

1 Answers1

1

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? however. Also consider what happens when the log gets rotated, if your system is configured to do this.

Community
  • 1
  • 1
Vercingatorix
  • 1,838
  • 1
  • 13
  • 22