I've got a log file that is rotated automatically when it reaches a certain size. The system keeps 5 rotated logs at a time, the older ones are deleted, and the lifetime of a log file is about 20 minutes.
The task is to monitor the log file (system.log) for a specified error code and when it occurs – to copy the file into another directory, before it is deleted.
I tried this:
tail -F system.log | grep -l "error code" | xargs cp /another/directory
but it returns "cp: taget 'input)' is not a directory"
Apparently this is because grep command does not return the file name as soon as the error code is found in it as I expected.
So I need some help here please.