简体   繁体   English

重新启动带有墙消息的邮件

[英]reboot mail with wall message

Im searching for a solution to the following: I use Ansible to orchestrate my infrastructure and when I patch my CentOS systems I reboot after the upgrades have finished using: /sbin/shutdown -r "Ansible Linux Updates triggered reboot". 我正在寻找以下解决方案:我使用Ansible来协调我的基础结构,并在修补CentOS系统时使用以下命令完成升级:/ sbin / shutdown -r“ Ansible Linux Updates触发了重启”。

Now what I'd like to get is an email with the message when the system is rebooted. 现在,我想获得的是一封电子邮件,其中包含系统重启时的消息。

In cron you can select the @reboot flag and mail it, but how do I get this message from my shutdown command into the cron, or is there a whole other solution to my question? 在cron中,您可以选择@reboot标志并将其邮寄,但是如何从我的shutdown命令将此消息发送到cron中,或者我的问题是否还有其他解决方案?

Thank you kindly for your assistance! 谢谢您的协助!

Two ways 两种方式

On your crontab 在您的crontab上

 @reboot /root/emailnotify.sh

On your /etc/rc.d/rc.local (if centos base) or /etc/rc.local (debian) add to end the line 在您的/etc/rc.d/rc.local(如果以centos为基础)或/etc/rc.local(debian)上,添加此行的结尾

#!/bin/sh
...
...
/root/emailnotify.sh

Create a file /root/emailnotify.sh 创建一个文件/root/emailnotify.sh

#!/bin/bash

sleep 60

IP=`hostname -i`
HOSTNAME=`hostname -f`
echo "$HOSTNAME online.  IP address: $IP" > /tmp/email.txt
echo >> /tmp/email.txt
date >> /tmp/email.txt

mail -s "$HOSTNAME online" -r restart@server.domain.tld myemail@mydomain.tld < /tmp/email.txt
mail -s "$HOSTNAME online" -r restart@server.domain.tld myotheremail@myotherdomain.tld < /tmp/email.txt
mail -s "$HOSTNAME online" -r restart@server.domain.tld mycellphone@txt.carrier.tld < /tmp/email.txt
rm -rf /tmp/email.txt

Executable file 可执行文件

chmod u+x /root/emailnotify.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM