4

I run this command

ss -tulpnoea|grep -i water|grep -v 127
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
Failed to find cgroup2 mount
.....

I tried with 2> /dev/null...

 ss -tulpnoea|grep -i water|grep -v 127 2> /dev/null
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    Failed to find cgroup2 mount
    .....

How to avoid the annoying message about cgroup2 mount? Distro is Slackware 15.0

elbarna
  • 12,050
  • 22
  • 92
  • 170
  • The `cgroup2` virtual filesystem is meant to be mounted on `/sys/fs/cgroup`, systemd takes care of that on systems that use it. Maybe you need to do it via `/etc/fstab` on Slackware? – Stéphane Chazelas Jun 02 '23 at 19:55
  • 2
    I'd say that's *maybe* a bug in `ss` (iproute2) – as long as it only uses cgroups for looking up some auxiliary info, it should not assume that cgroups are in use on the system at all, rather than complaining. – u1686_grawity Jun 03 '23 at 08:44

1 Answers1

13

You have your redirection at the wrong point in the pipeline. Presumably the error comes from the ss command, so that is where you should hide the error output. Or you can group the output and redirect from the command as a whole.

Here are some possible solutions to suppress any errors:

Redirect the standard error of the command producing the messages:

ss -tulpnoea 2> /dev/null|grep -i water|grep -v 127 

Run the commands in a subshell and redirect the standard error of the subshell:

(ss -tulpnoea|grep -i water|grep -v 127) 2> /dev/null

Group the commands and redirect the standard error of the group:

{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> /dev/null

Or if you specifically want to suppress that error and not others (subject to shell support)

ss -tulpnoea 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)|grep -i water|grep -v 127) 
(ss -tulpnoea|grep -i water|grep -v 127) 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)
{ ss -tulpnoea|grep -i water|grep -v 127 ; } 2> >(grep -Fxv 'Failed to find cgroup2 mount' >&2)
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
bxm
  • 4,561
  • 1
  • 20
  • 21