wall 命令基本介绍wallWrite All是 Linux 系统中用于向所有登录用户发送消息的命令。它可以向系统中所有登录用户的终端发送广播消息。wall是系统管理员向所有用户发送通知的重要工具。资料合集https://pan.quark.cn/s/6fe3007c3e95、https://pan.quark.cn/s/561de99256a5、https://pan.quark.cn/s/985f55b13d94、https://pan.quark.cn/s/d0fb20abd19a语法wall [OPTIONS] [MESSAGE]常用选项基本选项-n, --nobanner不显示消息头部-t, --timeoutSECONDS设置超时时间-h, --help显示帮助信息-V, --version显示版本信息使用示例1. 向所有用户发送消息wallSystem maintenance in 10 minutes输出示例Broadcast message from roothostname (pts/0) at 10:00 ... System maintenance in 10 minutes2. 从文件读取消息wallmessage.txt3. 不显示消息头部wall-nEmergency: System will reboot now!输出示例Emergency: System will reboot now!4. 输入多行消息wall Hello everyone!This is a reminder that we will be performing system maintenance tonight at10PM. Thank you, Admin结束输入按CtrlD结束消息输入。5. 设置超时时间wall-t5Important announcement6. 在脚本中使用 wall#!/bin/bash# 发送维护通知send_maintenance_alert(){localmessage$1echoSending maintenance alert to all users...wall$messageif[$?-eq0];thenechoAlert sent successfullyelseechoFailed to send alertexit1fi}# 使用示例send_maintenance_alertSystem maintenance scheduled for tonight at 10 PM.输出格式说明带头部的消息Broadcast message from roothostname (pts/0) at 10:00 ... System maintenance in 10 minutes不带头部的消息Emergency: System will reboot now!错误输出示例wall: cannot send message工作原理wall 执行流程# 1. 用户执行 wall 命令wallMaintenance alert# 2. 读取消息内容# 3. 获取所有登录用户列表# 4. 向每个用户终端发送消息# 5. 输出发送结果相关文件文件说明/var/run/utmp当前登录用户信息/dev/tty*终端设备文件实用技巧发送定时维护通知#!/bin/bash# 发送维护通知MESSAGE SYSTEM MAINTENANCE NOTICE Date:$(date%Y-%m-%d)Time: 10:00 PM The system will be undergoing maintenance tonight. Please save your work and log out before 10 PM. Thank you, System AdministrationechoSending maintenance notice...wall$MESSAGE结合 cron 使用# 添加到 cron 任务每天 9 AM 发送提醒# 编辑 cron 配置crontab-e# 添加以下内容09* * * wallGood morning! Dont forget to check your emails.发送紧急消息#!/bin/bash# 发送紧急消息send_emergency(){localmessage$1# 发送紧急消息不带头部更醒目wall-n EMERGENCY $messageechoEmergency message sent}# 使用示例send_emergencyNetwork outage detected! Please save your work.检查消息是否发送成功#!/bin/bashMESSAGETest message# 发送消息并检查结果ifwall$MESSAGE/dev/null21;thenechoMessage sent successfullyelseechoFailed to send messageexit1fi相关命令write向单个用户发送消息mesg控制终端消息权限talk与其他用户进行对话users显示当前登录用户who显示当前登录用户w显示当前登录用户及其活动注意事项权限要求普通用户可以使用 wall但某些系统可能限制目标用户消息发送给所有登录用户消息权限用户可以使用 mesg 禁止接收消息root 用户root 用户可以向所有用户发送消息结束输入按CtrlD结束消息输入超时设置可以使用 -t 选项设置超时时间总结wall是 Linux 系统中用于向所有登录用户发送广播消息的工具。它是系统管理员向所有用户发送通知的重要工具。wall可以发送单行消息、多行消息也可以从文件读取消息内容。