tail -f

gudii9
gudii9 used Ask the Experts™
on
tail -f logfile.log


what is the meaning of above command.

i see logs rolling too fast.

is there is a way i can slow it down to see clearly slowly

any god tips, links, resources on how to debug production logs efficiently just using putty without any fancy costly tools?

please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
Tail -f is monitor the log in realtime meaning you will see the entry as soon as it is added. If it is an active app, the lines will scroll as quickly as they are added.

man tail will tell you what the command is and what it is for.

grep if you have a pattern of interest
When troubleshooting, tail logfile will give you a snapshot of the entries.

Commonly, one looks for "error" though often an issue means the application has issues, so looking at the current entries is enough.

Each application has their own troubleshooting steps.

Understanding what the expected behavior of the application is simplifies the troubleshooting when an unexpected behavior occurs.

Please use the manual pages (man command, man -k keyword)

There are many guides that if searched for could help you troubleshoot what you are dealing with/having issues with.
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018
Commented:
Try tail -f logfile.log | more to have it scroll
Piping tail -f to more doesn't actually work correctly.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Rahul ShendeJr. Linux System Administrator
Commented:
tail -f logfile.log | less

then use down arrow to scroll down. you can use pg up, pg dn for scrolling up down
Piping it to less works partially, until you scroll all the way down again.  It will then stream for a while until the pager reaches a full page again.  The point of tail -f is to have a continuous stream.  Piping it to a pager defeats the purpose.  You might as well just use tail on the log file every once in a while as you need it.

Author

Commented:
tail -f logfile.log | more

what is difference between above and

 tail -f logfile.log | less

please advise

Author

Commented:
i liked below option

tail -f logfile.log | more

to see page then next page etc
Distinguished Expert 2017

Commented:
It tells you at the bottom, space will continue.

Please remember, man more will provide you guidance on ....
Don't expect it to work consistently.
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
Commented:
@gudii9
$ /bin/cat Display_35_lines.sh
#!/bin/bash
#Script having performance issue when ./logfile.log having more number of lines.
if [ -f ./logfile.log ]
then
	export TOTAL=$(/usr/bin/wc -l ./logfile.log | /bin/sed "s/ .*//;")
	export STARTLN=1;
	export ENDLN=$(( $STARTLN + 34 ));
	REMAINING_LINES=$TOTAL
	while [ $REMAINING_LINES -ge 1 ]
	do
		/bin/awk 'BEGIN {
			ENDLN=ENVIRON["ENDLN"];
			STARTLN=ENVIRON["STARTLN"];
		}
		{
			if ( ( ENDLN >= NR ) && ( STARTLN <= NR ) )
			{
				printf( "%d: %s\n", NR, $0);
			}
		}' ./logfile.log
		REMAINING_LINES=$(( $TOTAL - $ENDLN ))
		export STARTLN=$(( $STARTLN + 35))
		export ENDLN=$(( $ENDLN + 35 ))
		if [ $REMAINING_LINES -gt 0 ]
		then
			echo -e "$REMAINING_LINES more lines.\nDo not press F1, F2, till F12\nPress q to quit.\nPress any letter to continue: "
			read -n 1 STATUS
			if [ "q" = "$STATUS" ]
			then
				break
			fi
			/usr/bin/clear
		fi
	done
else
	echo "PWD $PWD"
	echo "/bin/ls ./logfile.log"
	/bin/ls ./logfile.log
fi
$

Open in new window

By default "/usr/bin/tail -f filename" displays last ten lines.
You can verify the same using
$ /usr/bin/tail -f ./logfile.log | /bin/grep -n $
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
$ # Pressed ctrl c

Open in new window

You can also perform following search:
$ /bin/grep -n SearchRequiredString ./logfile.log | /usr/bin/tail -1 | /usr/bin/awk -F: '{ print $1}'
290

Open in new window

SearchRequiredString last occurence present at 290th line number.
Using Display_35_lines.sh
replacing:
      export STARTLN=1
with:
      export STARTLN=290
$ /bin/sed -i "s/\(export STARTLN=\)1/\1290/" Display_35_lines.sh
$ /bin/grep -n "export STARTLN=[0-9]" Display_35_lines.sh
	export STARTLN=290;
$ ./Display_35_lines.sh
290: SearchRequiredString
291: /home/murugesandins/experts/nativeMessagingLauncher.exe
292: /home/murugesandins/experts/pkiclient-nativeMessagingLauncher.json
293: /home/murugesandins/sample1
294: /home/murugesandins/sample2
295: /home/murugesandins/sample3
296: /home/murugesandins/sample4
297: /home/murugesandins/sample5
298: /home/murugesandins/sample6
299: /home/murugesandins/sample7
300: /home/murugesandins/temp/sample10
301: /home/murugesandins/temp/sample9
$

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial