我正在尝试通过write
命令向自己发送一条消息,因为我希望一些脚本在后台运行,并能够将内容回显到我所在的终端。
因此,我总是遇到相同的错误,而且我不知道还能尝试什么:
user $: mesg y
user $: mesg
is y
user $: write myuser
write: myuser has messages disabled
echo 'hello' | write myuser
write: myuser has messages disabled
myuser $DISPLAY
write: myuser has messages disabled
echo 'hello' | write myuser $DISPLAY
write: myuser has messages disabled
为什么会发生这种情况?我该如何解决?
附言:我得到与 root 相同的结果。
答案1
您可以使用命令
who -T
在您的脚本中确定要使用哪个端口进行写入。'+' 或 '-' 字符表示终端是否可写。
[lion@FedoraXXI ~]$ who -T
lion ? :0 2015-04-24 15:18 (:0)
lion + pts/0 2015-04-24 19:58 (:0)
lion - pts/1 2015-04-24 21:24 (:0)
[lion@FedoraXXI ~]$
答案2
感谢 freenet 网络上的 ##linux 频道的评论,man mesg
我找到了答案,即:
myuser $: w
18:45:42 up 17:00, 2 users, load average: 4.10, 3.84, 3.52
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
myuser :0.0 01:46 ?xdm? 23:59 0.02s /usr/bin/ck-launch-session /usr/bin/dbus-launch --exit-with-session /usr/bin/i3
myuser $: sudo login myuser
Password:
Last login: Sun Apr 26 18:18:43 CEST 2015 on pts/6
myuser $: w
18:46:31 up 17:00, 3 users, load average: 4,11, 3,89, 3,56
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
myuser :0.0 01:46 ?xdm? 24:13 0.02s /usr/bin/ck-launch-session /usr/bin/dbus-launch --exit-with-session /usr/bin/i3
myuser pts/1 18:46 7.00s 0.86s 0.00s w
myuser $: echo "Now it works! :). Thanks to John1024 from http://superuser.com and <arvut> from ##linux channel in freenode's network :)" | write myuser /dev/pts/1
Message of myuser@tux the pts/1 at 18:50 ...
Now it works! :). Thanks to John1024 from http://superuser.com and <arvut> from ##linux channel in freenode's network :)
EOF
发生这种情况只是因为我使用了简约的图形设置,如果您使用任何正常的桌面环境,这种情况就不会发生。