LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-21-2012, 09:01 AM   #1
chesschi
Member
 
Registered: May 2011
Posts: 41

Rep: Reputation: 0
tail dmesg


I try to tail dmesg and pipe it to a file using watch:

i.e.
Code:
watch "dmesg -c | tail -f" >> tail_dmesg
However, it is not formatted properly and the newline is removed in the tail_dmesg file (all became one line).

Code:
^[[?1049h^[[1;54r^[(B^[[m^[[4l^[[?7h^[[H^[[2JEvery 2.0s: dmesg | tail -f^[[1;134HTue Aug 21 14:52:56 2012^[[3;1Husb 2-1: USB disconnect, address 11^M^[[4dusb 2-1: new low speed USB device using uhci_hcd and address 12^M^[[5dusb 2-1: configuration #1 chosen from 1 choice
What is the proper way to do this?
 
Old 08-21-2012, 10:58 AM   #2
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
Are you just trying to get the contents of the file in real time?
Cause the –c clears the buffer and then you write to a file with nothing there. The –f means to continually update on the screen – but then you use watch too?
Try doing:
Code:
# tail –f /var/log/dmesg >>tail_dmesg;
 
Old 08-21-2012, 12:48 PM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
If the previous reply doesn't solve your problem, then please clearly explain your goal. (Why are you doing this, and to what end?)
 
Old 08-22-2012, 02:56 AM   #4
chesschi
Member
 
Registered: May 2011
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by kbscores View Post
Are you just trying to get the contents of the file in real time?
Cause the –c clears the buffer and then you write to a file with nothing there. The –f means to continually update on the screen – but then you use watch too?
Try doing:
Code:
# tail –f /var/log/dmesg >>tail_dmesg;
Thank you for your reply.

My goal is to get the contents of dmesg in real time from a remote linux PC and put them into a file on my local PC. Unfortunately my remote linux system is embedded and does not contain the file /var/log/dmesg. That is why I try to use watch. The option -c will display the content first then clear the buffer (i.e. always show the latest content in dmesg). Then I attempt to "watch" the latest content and put it to a file but failed.

The actual command I used is:
Code:
watch ssh username@remote_host "dmesg -c | tail -f" >> tail_dmesg
Sorry for not stating my goal clearly

Last edited by chesschi; 08-22-2012 at 03:04 AM.
 
Old 08-22-2012, 03:20 AM   #5
chesschi
Member
 
Registered: May 2011
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by anomie View Post
If the previous reply doesn't solve your problem, then please clearly explain your goal. (Why are you doing this, and to what end?)
I googled tail dmesg and found that you have answered a similar post in linux forums before! Unfortunately my linux system have limited disk space and does not contain /var/log/dmesg. It would be great if you can suggest me another solution
 
Old 08-22-2012, 10:16 AM   #6
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
Try this :


Code:
# watch "dmesg -c >> tail_mesg"
 
Old 08-22-2012, 10:16 AM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
That's nice, but my answer in that ~7 year old thread is (unfortunately) incorrect. Please explain - in plan English - the goal you're trying to achieve. We can make guesses based on the pipeline you've cobbled together, but the most elegant solution may present itself once we understand you better.

Also, what OS / version are you using?
 
Old 08-22-2012, 06:07 PM   #8
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Those are control codes to manipulate the cursor and clear the screen.
"watch" is designed to operate directly on the terminal and not be piped or redirected.
 
Old 08-23-2012, 04:09 AM   #9
chesschi
Member
 
Registered: May 2011
Posts: 41

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by anomie View Post
That's nice, but my answer in that ~7 year old thread is (unfortunately) incorrect. Please explain - in plan English - the goal you're trying to achieve. We can make guesses based on the pipeline you've cobbled together, but the most elegant solution may present itself once we understand you better.

Also, what OS / version are you using?
I had a normal local linux PC (any OS) and a remote embedded non-standard linux PC. My remote embedded linux PC has been customised with limited package and has limited disk space (that's why there is no /var/log/dmesg). Therefore, I proposed to retrieve the contents in dmesg from the remote linux PC (limited disk space) and put it in my local linux PC (plenty of disk space). In order to do that, I used ssh command and execute the dmesg/tail/... command to get the contents of dmesg and then watch/pipe it to a file on my local linux PC. So it will become something like this:

Code:
watch ssh username@remote_host "dmesg -c" >> tail_dmesg
So I thought this command will ssh to remote_host and display the latest dmesg content(with -c option). So I watch this latest dmesg content and pipe it to the tail_dmesg file.

Hope now it is clear!

Last edited by chesschi; 08-23-2012 at 04:10 AM.
 
Old 08-23-2012, 01:52 PM   #10
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
If your remote, embedded Linux box has syslogd installed, you might want to consider doing remote logging for kern.* (or whatever facility/level you want) messages instead. Something like that is arguably a better solution.

Example entry in syslog.conf(5):
Code:
# Send certain messages to remote logger
kern.*                                                  @your.receiving.host
Regular syslogd only does UDP (and clear text, for that matter), so bear that in mind if your link between the two hosts is unreliable.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Difference between ouput of dmesg and content of /var/log/dmesg Sayan Acharjee Linux - General 1 09-21-2011 10:42 AM
dmesg vs /var/log/dmesg drManhattan Linux - Newbie 2 08-07-2011 05:28 AM
tail the output of tail -n 1 raj k yadav Linux - Newbie 5 02-06-2010 11:26 PM
dmesg (command) and /var/log/dmesg are different? Oxagast Linux - Software 2 07-10-2006 05:50 AM
/bin/dmesg > /dmesg-boot not Working in Knoppix 3.4 suguru Debian 2 07-04-2004 05:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:33 PM.

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