2

I am not able to successfully redirect STDOUT+STDERR on commands that operates with disks. Standard redirecting which always works, is somehow now catching the output. Two practical examples:

Example 1:

# wipefs --all --force /dev/sda >>/var/log/custom.log 2>&1

[   20.169018 ]  sda: sda1

Example 2:

# mount --verbose --options defaults --types ext4 /dev/sda1 /path/is/here >>/var/log/custom.log 2>&1

[   30.947410 ] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null)

Interesting is, that this only happens when touching disks somehow. All other redirects within the script works as expected.

Any ideas?

1 Answer 1

3

This is not output from the command, this is kernel log messages. Since the messages aren't coming from the command, they aren't affected by redirection.

Kernel log messages normally go into log files, and important messages are additionally shown on the console. Exactly what “important” and “the console” mean depend on the logging configuration. If you're using sysklogd, the configuration file is /etc/syslog.conf. If you're using rsyslog, it's /etc/rsyslog.conf and /etc/rsyslog.d/*. If you're using systemd's built-in logging, it's /etc/systemd/journal.conf. The kernel can also print logs to the console directly without going through a logging daemon, which can be configured with dmesg --console-… (but this is usually done indirectly via the configuration of the logging daemon).

1
  • Thanks. That was the right direction, indeed. For anyone else who wonders, how to manipulate the kernel log levels from terminal, you can you dmesg -n <value> Commented Jun 14, 2021 at 17:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.