7

So I have this cronjob on an Ubuntu 16.04 machine that ends in

if ...
  echo "warning" | wall 2>&1 > /dev/null
fi

that I use to warn all users about some action taking place. Although I redirect its output to /dev/null, the script somehow manages to output

wall: cannot get tty name: Inappropriate ioctl for device

which gets sent per e-mail to the root account. How do I make wall silent? The broadcasting works, but I don't want to have those e-mails in my root mailbox.

# wall -V
wall from util-linux 2.27.1
Pavel
  • 1,098

2 Answers2

9

Looking at the wall source it says this:

259          if (print_banner == TRUE) {
...
...
271                  where = ttyname(STDOUT_FILENO);

This ttyname call is the cause of your issue because cron doesn't run a TTY. It is doing this because the tty name is in the banner message I.E

Broadcast message from user@host (pts/0)

Based off of the logic however it wont try this if you dont tell it to print a banner. Its trivial to avoid this problem by invoking wall like this:

if ...
  echo "warning" | wall -n 2>&1 > /dev/null
fi

This should avoid the problem entirely. You'll need to supply your own banner however in the resulting output.

Matthew Ife
  • 24,261
2

The reason this isn't working the way you expect is because you have the two redirects specified in the wrong order. The order matters. You wrote:

wall 2>&1 > /dev/null

which means "redirect stderr to the same place stdout is currently going (usually a tty) and then redirect stdout to /dev/null". You should have written:

wall > /dev/null 2>&1

which means "redirect stdout to /dev/null and then redirect stderr to the same place stdout is currently going (which is now /dev/null)".