[SOLVED] Script For sending mail if disk is not mounted
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
if [ `mount |grep IP |wc -l` -eq 1 ];
then echo "it is mounted" >> somefile.txt;
else
echo "not mounted" |mail -s "not mounted" to.someone@who.cares.com;
fi
?
The only thing you might be concerned with is if that "grep" will still return that IP even if that mount is not truly accessible. For example, mount might show it mounted but in an error state. So you would be wise to add a further test to see if it is actually accessible by touching a file on the remote end (assuming you have write access) or just seeing if a known file exists. (like `if [ -d /known/file/at/remote/end]...).
Could you possibly post a command - how you send a usual mail / normal mail.
As for above "code" create a file test.sh
mark it executable
and paste that single line
execute script with "ip" mounted and discounted - and verify results.
This "/dev/null 2>&1;" part is confusing. could find some help on google - I could only understand that output is going to a null file. so does it mean it gets overwritten if i use this in multiple scripts running on Cron at same time? would this lead to an error??
This "/dev/null 2>&1;" part is confusing. could find some help on google - I could only understand that output is going to a null file. so does it mean it gets overwritten if i use this in multiple scripts running on Cron at same time? would this lead to an error??
/dev/null is your OS black hole, it isn't overwritten, it absorbs everything you send to it
2>&1 is a bash expression, it means send error output (#2) to standard output (#1)
So sending output > /dev/null 2>&1 means suppress both standard and error output
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.