在 CentOS 里“发送 message 告警”通常指 通过系统消息(wall / write / mesg)或日志(/var/log/messages)+ 告警通知 来实现。下面按常见场景给你讲清楚。
wall 发系统级消息所有登录用户都会收到:
wall "警告:磁盘使用率超过90%"
或写脚本:
echo "CPU负载过高,请检查" | wall
write username
然后输入内容,Ctrl+D 结束。
⚠️ 用户需开启 mesg y:
mesg y
CentOS 默认使用 rsyslog:
logger -p user.err "数据库服务异常,请检查"
查看:
tail -f /var/log/messages
常用级别:
user.infouser.warnuser.erruser.crit#!/bin/bash
USE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
if [ "$USE" -gt 90 ]; then
logger -p user.crit "磁盘使用率过高: ${USE}%"
wall "磁盘告警:使用率 ${USE}%"
fi
加入 crontab:
*/5 * * * * /opt/disk_alert.sh
echo "磁盘告警" | mail -s "CentOS Alert" admin@company.com
通常是调用 webhook(curl):
curl -X POST 'https://oapi.dingtalk.com/robot/send?access_token=xxx' \
-H 'Content-Type: application/json' \
-d '{"msgtype":"text","text":{"content":"CentOS 告警"}}'
❌ message 不是单独命令
✅ 实际是 /var/log/messages 或 wall/message 功能
如果你指的是:
告诉我具体场景,我可以给你现成配置。