I'm supposed to follow a logfile, I want to initiate a sed
command to edit conffile upon appearance of certain line in the log. I did little research and found out that it can be done with awk
.
and the syntax is like:
tail -f /path/to/serverLog | awk '
/Printer is on fire!/ { system("shutdown -h now") }
/new USB high speed/ { system("echo \"New USB\" | mail admin") }'
as proposed in this answer
so I wrote my own like with a sed
variant:
tail -f logfile | awk '/^Jit ended**/ { system("sed -E '/^Jit/{s/enabled=false/enabled=true/; s/From=[0-9]+-[0-9]+-[0-9]+/From=2021-02-01/}' conffile") }'
but it doesn't work, and throws errors like
(^ syntax error|^ unterminated string)
I guess this is to do something with {}
in the sed
command not getting compatible with awk
syntax, but no idea where exactly, and how to get it work.
sed
expression) inside a single-quoted string constant (theawk
program) ... that won't work, unfortunately. – AdminBee Oct 05 '21 at 15:29sed
fromawk
can most likely be done inawk
directly. – Kusalananda Oct 05 '21 at 15:32-i inplace
, just like GNU sed has-i
but awk is a tool to manipulate text while a shell is the tool to manipulate files and processes and sequence calls to commands - you're trying to use awk as if it was a shell, don't do that. – Ed Morton Oct 05 '21 at 16:41