-1

I have log file system that renames the latest log file with current time and i must set a less command to check log file easily. I can quit less sommand with q but i must follow the latest incoming lines so after pressing shift+f q doesnt work and i need to quit with ctrl+c.

When i press ctrl+c main screen and process is being killed but terminal screen has the error that you can see below

terminal error

find /data/tomcat/logs/out.* -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" " |xargs less

i can clear the error with reset but its ridiculous to use it like this. As i search on internet most of people explained it as ctrl+c kills the main command but the script doesnt respond the SIGINT. Tried a lot of them but cannot succeded on killing this simple script.

And also unable to make aliases because some of the arguments gave error but it works perfectly fine when i run this command on terminal.

I know it would be easier to use logger rotate to rename the old file and keep the latest file with the same name but its not gonna happen.

1 Answers1

0

When you press shift-F while running less, it puts you into follow mode. Press Ctrl-C to exit this mode, then you can press Q to exit.

It sounds like the terminal echo is disabled when you break out of your command. It's the same thing that happens if you run stty -echo. To reset your terminal you can type stty sane. You'll have to type it blindly since you won't be able to see what you're typing, but it should work.

If you're not able to make an alias from the command line you provided, try putting it in a file and make it executable, then either make sure that script file is in your path, or make an alias to run it. You might also want to add a second line to your script that runs stty sane to ensure the terminal echo is enabled when the less command exits. Something like this should work:

#!/bin/bash
find /data/tomcat/logs/out.* -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" " |xargs less
stty sane
virtex
  • 441
  • 2
  • 4
  • 9
  • Hi virtex, thank you stty sane just do the job. As you said crtl+c doesn't behave like it should on follow mode but its just fine. – Firat Yilmaz Nov 24 '16 at 07:22