Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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:
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.
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
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.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
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.
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:
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.