Solved

Bash Script-Trigger email when server reboots

Posted on 2016-09-26
11
76 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
  • 4
  • 3
  • 2
11 Comments
 
LVL 35

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 35

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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 35

Accepted Solution

by:
Kimputer earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell Script need assistance to make some changes 4 85
centos commands 6 54
linux 13 55
Using sort and uniq to pare down large syslog 6 38
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…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

825 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