0

I'm using less to continuously trace Squid log file (as well as UFW log) with this command:

less --follow-name -K +F /var/log/squid/access.log

And at the time of rotation of Squid log less quits. I guess this happens because when an old file is renamed the new one is not created immediately but with a delay, though in the case of UFW log file this doesn't happen and less successfully switches to the new file.

So is there a method or option to make less wait for a new file to appear?

10
  • I can't reproduce the behaviour you're describing with less version 643 on Debian testing. Where I do see it waiting for the file to reappear whether I rename or delete the original. Commented Nov 17, 2024 at 10:30
  • @StéphaneChazelas I'm on Ubuntu 24.04.1, less is 590 (all the latest updates are installed). If I get it right less is a system package and for some reason the latest available version is from 2021. How can I manually upgrade less to the latest version? Commented Nov 17, 2024 at 18:47
  • FWIW, I can't reproduce with 590 nor 418 either. Can you describe a modus operandi where you manage to reproduce the issue. For instance, with seq 1000 > file; less --follow-name -K +F file, and then from another terminal rm file or mv file file2, and then seq 100 > file I can't reproduce it. Commented Nov 17, 2024 at 18:51
  • The closest I can get to your issue is if I recreate the file with it being inaccessible like with (umask 666; seq 100 > file) in which case less issues a file: Permission denied (press RETURN) and exits when I press Return Commented Nov 17, 2024 at 18:55
  • @StéphaneChazelas I just run the command less --follow-name -K +F /var/log/squid/access.log and less successfully shows me the log file but when I open the console tab shortly after midnight I see less quit and I have to run the command again. Commented Nov 17, 2024 at 19:08

1 Answer 1

-1

If tail --retry does work you can just pipe that into less instead of opening the file directly:

tail -F /var/log/squid/access.log | less
2
  • 1
    Can you please write an example of how can I do it on Ubuntu? Commented Nov 17, 2024 at 19:15
  • @StephenKitt, thank you, I added the options from my initial command to less (tail -F /var/log/squid/access.log | less -K +F) and it seems now less doesn't quit on log rotation and keeps following the new file. Commented Dec 2, 2024 at 17:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.