Solved

Bash Script-Trigger email when server reboots

Posted on 2016-09-26
11
84 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SMB share across internet 15 79
Upgrade BIOS / EUFI at Scale 4 69
Samba 4, Users Permission, 5 62
regular expression help for sed command 5 39
If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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