I’m trying to tail a log through the duration of a bash script that involves multiple reboots. The point is to be able to watch the main log to verify what the script is logging. The script runs some code before rebooting. This is repeated an n amount of times that is specified by the user.
tail -f /var/log/syslog >> /home/user/syslogTracker.txt TAILPID=$! ... ...Functionality of the script... ... kill $TAILPID
The problem with this is that it hangs the program and it never gets off of the tail. Is there a way to invoke this and still run the program? I imagine as long as the tail is killed before reboot and it appends again after a reboot that would work fine.
Advertisement
Answer
Change the line to:
tail -f /var/log/syslog >> /home/user/syslogTracker.txt &
This puts the tail -f
to background
As you have it now, tail -f
intentionally is going to never finish (as is stays in the foreground forever / until killed), so you would never get to the next line..