Goal: using sudo execute a one line cmd to tail a log until a string is found and then exit 0. If the string is not found within a given timeout, exit anything but 0.
Attempted Solution 1: Originally I did not have timeout as a requirement and so after some research I landed on using:
sudo sh -c '( tail -n1 -f /path/to/nameOfLog.log & ) | grep -q "Started .*Application"'
However, now I do have timeout as a requirement. I could not figure out how to get timeout to work with this command until I found Ondra Žižka's answer. So my new cmd became:
Attempt Solution 2:
timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)
But this obviously is not using sudo permissions, which is the current issue I need to solve. Below are some variations I've tried which failed
Try 1 : (add sudo in front of cmd)
sudo timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)
grep: /dev/fd/63: No such file or directory
Try 2: (try to wrap cmd in subshell)
sudo sh -c 'timeout 5 grep -q "Started .*Application" <(tail -n1 -f /path/to/nameOfLog.log &)'
sh: 1: Syntax error: "(" unexpected
Can someone show me and explain the issue and how to fix it so I can run this command using sudo? Also, do I really need to restructure cmd from Attempted Solution 1 to get it to work with timeout as well?