LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 12-10-2009, 04:13 AM   #1
v0nd00
LQ Newbie
 
Registered: Dec 2009
Posts: 9

Rep: Reputation: 0
Cannot use tail -f to monitor log file


I use tail -f on /var/log/messages to check the latest update on the log file. It show last 10 line of the file and
command continue to run but didn't show the update of the log file (real time).
As I know , the command should show latest entry to the log file time to time


I use this "tail -f /var/log/messages"

pls anyone guide me what did i do wrong.
 
Old 12-10-2009, 04:46 AM   #2
aus9
LQ 5k Club
 
Registered: Oct 2003
Location: Western Australia
Distribution: Icewm
Posts: 5,842

Rep: Reputation: Disabled
I am not sure you are doing anything wrong....have you checked that there were changes?

I had to use /log/auth.log and open and close a root terminal to prove it works ok for me
tail -f /var/log/auth.log
 
Old 12-11-2009, 12:07 AM   #3
v0nd00
LQ Newbie
 
Registered: Dec 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by aus9 View Post
I am not sure you are doing anything wrong....have you checked that there were changes?

I had to use /log/auth.log and open and close a root terminal to prove it works ok for me
tail -f /var/log/auth.log
I tried with tail -f /var/log/auth.log it is working but i cannot monitor like this to every file

Can you tell me why ?


I create a file with touch "touch test "and tried to change the file during the monitoring period (tail -f touch )but tail -f shows nothing .



Please explain me


thank you for your help
 
Old 12-11-2009, 12:40 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
tail -f is not showing anything because the file is empty and not changing
Code:
c:/tmp$ touch foo
c:/tmp$ tail -f foo
[nothing displayed until did echo wibble > /tmp/foo in another terminal when got ...]
wibble
 
Old 12-11-2009, 12:52 AM   #5
v0nd00
LQ Newbie
 
Registered: Dec 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
tail -f is not showing anything because the file is empty and not changing
Code:
c:/tmp$ touch foo
c:/tmp$ tail -f foo
[nothing displayed until did echo wibble > /tmp/foo in another terminal when got ...]
wibble

Sorry I forgot to mention that After "touch"
I "vim touch test" and add some line but


In the mean time I run tail -f from the beginning but shows nothing .
 
Old 12-11-2009, 01:18 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You created a new file which tail is not monitoring. Instead open two terminals in the same directory. run:
touch testfile
tail -f testfile

Now in the second terminal, run "ls >>testfile.

When a program opens a file, it gets a file descriptor back, which is an integer. This file descriptor is used for further reads and writes.

When you saved the file you loaded in vim, you created a new file with a new inode. The tail command still has the original file open. It won't be closed until you quit "tail -f" by pressing CTRL-C. After doing that, the kernel will delete the file.

Code:
touch testfile2
jschiwal@netcow:~/Download> ls -li testfile2
5963813 -rw-r--r-- 1 jschiwal jschiwal 0 2009-12-11 01:05 testfile2
jschiwal@netcow:~/Download> tail -f testfile2

vim testfile2
jschiwal@netcow:~/Download> ls -li testfile2
5963815 -rw-r--r-- 1 jschiwal jschiwal 28 2009-12-11 01:05 testfile2

ps -C tail
  PID TTY          TIME CMD
19111 pts/3    00:00:00 tail
jschiwal@netcow:~/Download> ls -l /proc/19111/fd/
total 0
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:08 0 -> /dev/pts/3
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:08 1 -> /dev/pts/3
lrwx------ 1 jschiwal jschiwal 64 2009-12-11 01:07 2 -> /dev/pts/3
lr-x------ 1 jschiwal jschiwal 64 2009-12-11 01:08 3 -> /home/jschiwal/Download/testfile2~ (deleted)

jschiwal@netcow:~/Download> lsof +L1
COMMAND     PID     USER   FD   TYPE DEVICE SIZE/OFF NLINK    NODE NAME
amarok    13605 jschiwal   15u   REG    8,6        0     0  770202 /tmp/ibAniGv6 (deleted)
amarok    13605 jschiwal   16u   REG    8,6        0     0  770205 /tmp/ibHBfmQS (deleted)
amarok    13605 jschiwal   17u   REG    8,6        0     0  770210 /tmp/iboYw2aF (deleted)
amarok    13605 jschiwal   18u   REG    8,6        0     0  770211 /tmp/ibEJsPxr (deleted)
amarok    13605 jschiwal   22u   REG    8,6        0     0  770212 /tmp/ib8sR5ce (deleted)
kio_file  18035 jschiwal  txt    REG    8,6    48648     0 1803959 /usr/bin/kdeinit4 (deleted)
tail      19111 jschiwal    3r   REG    8,7        0     0 5963813 /home/jschiwal/Download/testfile2~ (deleted)

...
As you can see, it is common for programs to create temporary files, delete them, but continue to use the file descriptors to write to them. If the program crashes, the temporary file will be removed by the kernel automatically. It also solves the problem if the psuedo random filename of another program's temporary file happens to have the same name. It doesn't matter, the program won't be blocked from creating a new file.

Last edited by jschiwal; 12-11-2009 at 01:25 AM.
 
Old 12-11-2009, 01:26 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by v0nd00 View Post
Sorry I forgot to mention that After "touch"
I "vim touch test" and add some line but


In the mean time I run tail -f from the beginning but shows nothing .
Works for me but only after writing the file from within vim (and gives error on making file shorter)
Code:
c:/tmp$ rm foo
c:/tmp$ touch foo
c:/tmp$ tail -f foo
[In vi (vim): ii:w]
i
[In vi (vim): d:w]
tail: foo: file truncated
 
Old 12-11-2009, 02:05 AM   #8
v0nd00
LQ Newbie
 
Registered: Dec 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by v0nd00 View Post
Sorry I forgot to mention that After "touch"
I "vim touch test" and add some line but


In the mean time I run tail -f from the beginning but shows nothing .
I got it now , it is working

thank you
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
convert LAN IP address to Host Name when I give cmd tail -f /var/log/squid/access.log rs15 Linux - Networking 6 01-22-2012 01:45 AM
Perl or PHP Script that can tail /var/log/auth.log - two-factor authentication tdnnash25 Linux - Server 1 06-18-2009 08:36 PM
shell script to monitor log file calipryss Linux - Newbie 14 08-05-2008 10:46 PM
monitor log file ufmale Linux - Newbie 3 05-09-2008 12:57 PM
tail -$NUM log chrisk5527 Linux - General 1 06-30-2004 09:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 04:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration