How to email admins automatically after a Linux server starts?

Managing a cluster of servers, I would like to notified when a server is started.

How to make the Linux servers email me or other admins automatically after they are started?

I did this by adding a crontab entry on each servers like

@reboot date | mailx -S smtp=smtp:// -s "`hostname` started" -r

Here, @reboot makes the script invoked after reboot.

For the usage of mailx, please check:

Sending Email Using mailx in Linux Through Internal SMTP

Sending Email from mailx Command in Linux Using Gmail’s SMTP

mailx man page

Also note that on Debian, Ubuntu, Linux Mint and others, you may need to install heirloom-mailx instead of the default mailutil.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *