Bash Script-Trigger email when server reboots

Hi Team,

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

Thanks
Vinayak
vinayaksshAsked:
Who is Participating?
 
KimputerConnect With a Mentor Commented:
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
 
KimputerCommented:
start seperate script, or include code in /etc/rc.local
0
 
vinayaksshAuthor Commented:
Please let me know the steps as i am not aware

Thanks
Vinayak
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
KimputerCommented:
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
 
vinayaksshAuthor Commented:
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
 
Kent WSr. Network / Systems AdminCommented:
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
 
vinayaksshAuthor Commented:
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
 
Kent WSr. Network / Systems AdminCommented:
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
 
vinayaksshAuthor Commented:
Given Solution worked fine

Thanks
Vinaayak
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.