大网数据广告活动
服务器运维问答

How to silently broadcast a warning from a cronjob via "wall"?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-11-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。