我如何广播消息到所有bash终端在python使用wall命令与stdin? [英] How do I broadcast messages to all bash terminal in python using wall command with stdin?

查看:227
本文介绍了我如何广播消息到所有bash终端在python使用wall命令与stdin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的raspbian上的所有bash终端广播消息。

I wanted to broadcast message to all the bash terminal on my raspbian.

我知道有wall命令执行这个步骤,我可以使用os.system python模块执行命令。

I understand that there's wall command to perform the step and I could use os.system python module to execute the command.

但是,运行命令wall text.txt需要sudo权限。有什么方法使用wall命令与stdin从python吗?

However, running the command "wall text.txt" requires sudo privilege. Is there any way to use wall command with stdin from python?

推荐答案

确实需要一个超级用户才能运行 wall 输入文件 man 说:

It is indeed required to be a superuser to run wall with an input file, man says:

NAME
     wall - write a message to users

SYNOPSIS
     wall [file]

DESCRIPTION
     Wall displays the contents of file or, by default, its standard input, on the terminals of all currently logged in users.

     Only the super-user can write on the terminals of users who have chosen to deny messages or are using a program which automatically denies messages.

     Reading from a file is refused when the invoker is not superuser and the program is suid or sgid.

但您可以这样做:

$ echo hello hello >text.txt
$ python                    
Python 2.7.1 (r271:86832, Mar 18 2011, 09:09:48) 
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.system('cat text.txt | wall')

Broadcast Message from mak@vader                                             
        (/dev/pts/14) at 10:31 ...                                             

hello hello                                                                    


Broadcast Message from mak@vader                                            
        (/dev/pts/14) at 10:31 ...                                             

hello hello                                                                    

0
>>> 

这篇关于我如何广播消息到所有bash终端在python使用wall命令与stdin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆