简体   繁体   中英

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".

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?

Thank you kindly for your assistance!

Two ways

On your 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

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

Create a file /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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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