问题原文
原帖链接 · Pavel · CC BY-SA 3.0
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
已采纳解答
原帖链接 · Matthew Ife · CC BY-SA 3.0
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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
