How to write to kernel log

hello

for example I am using logger to write messages to system log

  1. is there some way write to kernel log ??

or question number 2`

  1. I am using openwrt x64 on netbook.
    as I understood netbook's display shows kernel log on a real-time basis.
    is there ways to write your own messages on display in addition to kernel log and others???

thanks

Yes. Using bash:

echo MESSAGE > /dev/kmsg

About 2. can you clarify?

2 Likes

thanks for answer :slight_smile:

I mean that display is configured in such way that shows kernel log

if you press any key you are in command line mode

so it is possible to have your independent way also print on that display? I mean not only by writing to kernel log

Kernel log can be seen using "dmesg" command.

But if you have an open console (tty) then you can see some of messages that kernel:
https://www.kernel.org/doc/html/latest/core-api/printk-basics.html

The log level specifies the importance of a message. The kernel decides whether to show the message immediately (printing it to the current console) depending on its log level and the current console_loglevel (a kernel variable). If the message priority is higher (lower log level value) than the console_loglevel the message will be printed to the console.

But if you need to write to other console then this is how to do it:

1 Like

actually if I need console access to openwrt mostly I use putty
I am not using keyboard and display on openwrt netbook for that purposes
..

logger I use in my scripts for info or debug
but I wanted also something print on display to
your suggested echo MESSAGE > /dev/kmsg is what I need thank you

in addition (my second question) I was curious to know how to write on netbook display(in scripts) directly
not through kernel log

/dev/pts/ptmx

as I understood this one is tty of netbook's display

and I can write there in this way ??

echo MESSAGE > /dev/pts/ptmx

update
I tested that command right now
and it not printed on display

echo "MESSAGE" > /dev/tty0

this one works :slight_smile:
thank you

PS
also
echo "MESSAGE" > /dev/tty1 works

how to understand this??

is there difference between tty0 and tty1??

is there preferred one to use??

Here is what is "ptmx" device:

that is hard to understand for me :slight_smile:

anyway how I was supposed to now that what I need is /dev/tty0 or /dev/tty1 ??
I clearly guessed it.

and is there difference between tty0 and tty1??

Yes - there is difference.

Here is example from real machine:

blah    pts/1        123.123.123.123   Tue Nov  3 16:40 - 16:58  (00:18)
blah    pts/2        123.123.123.123   Tue Nov  3 15:14 - 16:38  (01:23)
blah    pts/1        123.123.123.123   Tue Nov  3 14:46 - 16:40  (01:53)
blah    pts/0        123.123.123.123   Tue Nov  3 14:38 - 16:59  (02:20)
blah    tty1                          Tue Nov  3 14:22 - down   (00:02)
blah    tty1                          Tue Nov  3 14:14 - down   (00:05)
blah    tty2                          Tue Nov  3 14:11 - down   (00:02)
blah    tty1                          Tue Nov  3 14:08 - down   (00:04)

So this is result from command "last" that shows all successful logins. As you can see there is user "blah" but he is connected few ways. When there is tty1 or tty2 this mean that user is physically sit on computer and login locally. First console is tty1, but seems that user is login also on second console (using Alt-F2) tty2.

But sometime you don't know on what console you're sitting and can be even on tty5 or even more. But you need something to be shown on CURRENT (!!!) console. That's why you can use tty0 and using tty0 shows things on current console.

That's why on your situation tty0 and tty1 are same.

But if user is logging-in remotely using SSH then there are consoles like pts/0, pts/1, pts/2 and so on.

1 Like

You can read more about consoles here:

I am connected through putty SSH to openwrt netbook from my notebook
and when I type there

echo "MESSAGE" > /dev/tty0
or
echo "MESSAGE" > /dev/tty1

result appears on netbook's(openwrt) display
NOT on ssh remote terminal on my notebook

thanks for link I'll try read and understand :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.