Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bash Script-Trigger email when server reboots

Posted on 2016-09-26
11
Medium Priority
?
106 Views
Last Modified: 2016-09-29
Hi Team,

I would like to write a script which should trigger email when server reboots automatically.Please help me out here

Thanks
Vinayak
0
Comment
Question by:vinayakssh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
11 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 41815997
start seperate script, or include code in /etc/rc.local
0
 

Author Comment

by:vinayakssh
ID: 41816000
Please let me know the steps as i am not aware

Thanks
Vinayak
0
 
LVL 36

Expert Comment

by:Kimputer
ID: 41816010
add this to your /etc/rc.local file, then reboot, you'll see it will mail you:

MESSAGE="Linux machine booted/n"

echo $MESSAGE | mail -s "Linux machine booted" "your_email@address.com"

Open in new window


Obviously, only works if your mail system is properly set up.
Run rc.local a few times to test if it works, then reboot for one final test.
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

Author Comment

by:vinayakssh
ID: 41816243
Hi,

Thanks for your help it is working fine as excepted.I would like to know same thing can be scheduled from cron job as well instead of putting in rc.local file

Thanks
Vinayak
0
 
LVL 12

Expert Comment

by:Kent W
ID: 41816329
Yes, it can
Crontab entry -

@reboot /path/to/mailscript.sh

You will need to move the commands out of the rc.local and place in a separate executable shell script (x permissions by the cron job running user)

If you are using Ubuntu, you may have to make the crontab entry as such:

@reboot root /path/to/mailscript.sh
0
 

Author Comment

by:vinayakssh
ID: 41821838
Thanks for your solution and it is working fine.

Please let me know if you have any link for learning the bash script for beginners

Thanks
Vinayak
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 41821906
If the solution was provided here, you should award points to the person(s) who helped you.
If you award yourself 0 points, it really means you did everything yourself, and the answer was NOT provided by anyone (which clearly isn't the case here)
0
 
LVL 12

Expert Comment

by:Kent W
ID: 41822176
I would also like to interject OP also asked, specifically, if this script could be ran via crontab on reboot, of which I gave the corresponding answer.
0
 

Author Closing Comment

by:vinayakssh
ID: 41822936
Given Solution worked fine

Thanks
Vinaayak
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question