Script For sending mail if disk is not mounted
Hello,
I'm just starting out, Please help in writing a script for - mount | grep "ip" if [mounted ] then echo - it is mounted >> somefile.txt else send mail - not mounted |
To literally answer your question, how about:
Code:
if [ `mount |grep IP |wc -l` -eq 1 ]; 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]...). |
Cool! thanks...
bad i couldnt crack this :):redface: |
Code:
[[ -z `mount | grep -i ip` ]] && echo " Not Mounted" || echo "Mounted" |
we use mail , dint even know about mutt
|
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. |
Or just grep /proc/mounts
Code:
|
Hi,
I use this syntax -> mail -s "test" someone@somwhere.com |
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??
|
Quote:
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 |
This single line should do the trick
create a empty file - copy this code - chmod +x - You are all set Code:
[[ -z `mount | grep -i ip` ]] && mail -s "ip not mounted" someone@somwhere.com |
Nice but does not fit OP requirement (when ip is mounted, write line to a text file)
|
Quote:
Code:
[[ -z `mount | grep -i ip` ]] && mail -s "ip not mounted" someone@somwhere.com || echo "ip is mounted" |
I have a question with this type of script line
Say the ip is not mounted, then it does an attempt to send mail, but if for some reason mail command fails, will it echo "ip is mounted" ? |
Quote:
---- Correct would have been this one Code:
[[ ! -z `mount | grep -i ip` ]] && echo "ip is mounted" || mail -s "ip not mounted" someone@somwhere.com |
All times are GMT -5. The time now is 12:24 AM. |