Debian 消息内容自定义指南
一 系统日志模板 rsyslog
$template CustomTemplate,"/var/log/custom/%$YEAR%-%$MONTH%-%$DAY%.log"
*.* ?CustomTemplate
& stop
sudo systemctl restart rsyslog
logger "Test custom rsyslog message"
ls /var/log/custom/
if $programname == 'myapp' then /var/log/myapp.log
& stop
以上做法基于 rsyslog 模板与规则配置,修改后需重启服务生效。二 邮件通知模板
sudo nano /etc/aliases
support: "|/usr/bin/printf 'Subject: %s\\n\\n%s' 'Support Ticket' 'Dear %s,\\n\\nYour support ticket has been received.'"
sudo newaliases
echo "Test email body" | mail -s "Test Subject" your-email@example.com
三 登录前后提示信息
echo -e "\n=== Debian System ===\nLast update: $(date)\nVersion: $(lsb_release -ds)" | sudo tee /etc/issue
echo "Welcome to Debian Server! Today is $(date +%F)." | sudo tee /etc/motd
四 桌面通知与定时提醒
sudo apt install libnotify-bin
notify-send "标题" "消息内容"
notify-send -u critical -i dialog-warning "构建失败" "发现 <b>123</b> 个错误。"
sudo apt install at
echo "notify-send '会议提醒' '14:00 有项目会议'" | at now + 5 minutes
sudo apt install dunst
mkdir -p ~/.config/dunst
cp /usr/share/doc/dunst/examples/dunstrc ~/.config/dunst/dunstrc
# 编辑位置、颜色、超时等后重启会话或通知服务
五 自动化与安装阶段消息
d-i preseed/late_command string \
in-target echo "Welcome to your new Debian system!" > /target/etc/custom-message.txt
sudo tee /etc/systemd/system/boot-notify.service >/dev/null <<'EOF'
[Unit]
Description=Boot Notification
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/notify-send "系统已启动" "当前时间: $(date)"
User=your-username
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/your-username/.Xauthority
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now boot-notify.service
# 每天 09:00 提示
0 9 * * * /usr/bin/notify-send "早安" "请检查系统状态"