I am looking for a script which does the following
Script will run daily.
1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts.
2.Then it will compare new snapshot with the snapshot created in the previous run.
3.If filesystem exists in previous day snapshot and in new snapshot save file system in snapshot and continue.
4.If filesystem exists in new snapshot and does not exist in the previous day snapshot send an e-mail .
5.If filesystem exists in the previous day snapshot and does not exist in new snapshot send e-mail with high priority indicating the potential problems.
thx a lot !
sai
# I think the hostname is available as the preset var HOSTNAME.
# HOSTNM=`hostname`
DATE=$(date +"%d-%b-%y %H:%M")
SHORTNAME="FileSystem Mount"
LONGNAME="Filesystem check"
#I don't think grep supports |, just egrep.
# You can also break apart really, really long lines with backslashes
# so that it doesn't stretch your editor 3 miles wide.
#checking filesystem if its mounted or not
#df -k |grep '/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|... >d.txt
# You can't just stick a file into []'s and expect it to work!
# You're probably trying to check the return code of grep instead, right?
# unfortunately, grep isn't going to work here since it'll return OK even if it
# finds only ONE of these filesystems.
#if [ d.txt == "1" ]
#then
#mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
#else
#mail -s "Filesystem check success $DATE HOSTNM " xx@domain.com
#fi
#exit
SUCCESS=0
# Create a temp file with a secure random name.
TMP=`mktemp`
df -h >$TMP
# Loop through each of these filesystems/paths individually.
# if I knew AIX well enough I might try reading from /etc/fstab instead
for DEV in /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
/proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
/dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
/dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
/dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
/dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
/dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
/dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
/dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
/dev/expoptzloclv /dev/performlv|/dev/sshcntllv
nasswd10v1prd\.nam\.nsroot\.net:/vol/ClearCase/cbnabi \
cchome01\.core\.afcc\.com:/export/home
do
# Check if grep can find the device in the file. If not, set SUCCESS=1.
# The -q flag tells grep to not print anything, all we need is the return code.
grep -q "${DEV}" "${TMP}" || SUCCESS=1
done
# Delete the temp file.
rm -f "$TMP"
if [ "${SUCCESS}" -eq 0 ]
then
mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
else
mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
fi
Pls advice me if this logic works good as i find /etc/filesystems as aix dont have fstab
I hope this script logic is simple and less .Thanks for your advice .Pls advice anything wrong here
I am comparing the original etc/filesystem and todays .after comparing i will redirect it to a tmp file
pls advice again..U are gr8 would like your email address and phone number so that i can get good advice as i am looking for help for writting another script also
DATE=$(date +"%d-%b-%y %H:%M")
SHORTNAME="FileSystem Mount"
LONGNAME="Filesystem check"
TMP ="/home/cchome01/km17590/temp"
#I am storing the snapshot of the original filestem in /etc/filesystems as original.txt in my home directory
cat /etc/filesystems > today.txt
cmp original.txt today.txt >$TMP
grep -q "${TMP}" || SUCCESS=
if [ "${SUCCESS}" -eq 0 ]
then
mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
else
mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
#Delete the temp file.
rm -f "$TMP"
fi
I am not able to crop the script what you had mentioned ..Appreciate if you can crop it and sent it ..
thx a lot !
sai
---------- Post updated at 02:39 PM ---------- Previous update was at 01:47 PM ----------
km17590@cbnap001c[20# ./gopalan
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 1048576 907448 14% 3929 2% /
/dev/hd2 2555904 1377372 47% 35234 10% /usr
/dev/hd9var 2097152 1955096 7% 2176 1% /var
/dev/hd3 3145728 3141496 1% 19 1% /tmp
/dev/hd1 2097152 2096484 1% 6 1% /lhome
/proc - - - - - /proc
/dev/hd10opt 2097152 972580 54% 8828 4% /opt
/dev/exportlv 65536 64140 3% 7 1% /export
/dev/optwarelv 65536 64156 3% 5 1% /optware
/dev/orabinlv 2097152 2088308 1% 5 1% /optware/oracle
/dev/ndmbinlv 1048576 877836 17% 1485 1% /opt/cdunix
/dev/oraclntlv 4849664 2493804 49% 8768 2% /opt/oraClient
/dev/optswlv 10551296 8495064 20% 6072 1% /opt/sw
/dev/cbnadlv 65536 64136 3% 19 1% /cbnad
/dev/cbnabkplv 65536 64140 3% 8 1% /cbnabkp
/dev/lvabinit1 3145728 2052348 35% 5968 2% /opt/sw/abinitio
/dev/lvappl 4849664 4091500 16% 6307 1% /cbnad/data/appl
/dev/lveme 10354688 6994392 33% 89 1% /cbnad/data/eme
/dev/lvadmd1 10354688 10263764 1% 1338 1% /cbnad/data/admin
/dev/lvserial 314572800 305906528 3% 1382 1% /cbnad/data/serial
/dev/lvdata01 681574400 544718576 21% 1371 1% /cbnad/data/data01
/dev/lvdata02 681574400 544556824 21% 1370 1% /cbnad/data/data02
/dev/lvdata03 681574400 545085816 21% 1370 1% /cbnad/data/data03
/dev/lvdata04 681574400 544268116 21% 1370 1% /cbnad/data/data04
/dev/lvmeta1 10485760 10442876 1% 4 1% /cbnad/data/meta
/dev/lvabini1 2097152 2075244 2% 3026 1% /cbnad/data/abinitio
/dev/lvstage1 283115520 189556728 34% 2183 1% /cbnad/data/stage
/dev/lvfeed1 1730150400 1722278156 1% 491 1% /cbnad/feed
/dev/lvstage2 2228224 2218340 1% 4 1% /stage
/dev/lvcmmigr 1048576 1039896 1% 4 1% /cmmigr
/dev/lvbkdata1 131727360 131191920 1% 4 1% /cbnabkp/data01
/dev/lvbkdata2 131727360 131191920 1% 4 1% /cbnabkp/data02
/dev/lvbkdata3 131727360 131191920 1% 4 1% /cbnabkp/data03
/dev/lvbkdata4 131727360 131191920 1% 4 1% /cbnabkp/data04
/dev/lveers1 524288 519784 1% 4 1% /cbnad/EERS
/dev/expoptibmlv 6291456 3149788 50% 26575 4% /export/opt/IBM
/dev/expoptzloclv 10485760 6085100 42% 12920 1% /export/opt/z_local
/dev/performlv 786432 584864 26% 2021 2% /opt/perform
/dev/sshcntllv 1048576 1039892 1% 5 1% /opt/sw/sshcntl
nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi 61656272 52672936 15% 4079 1% /net/nasswd10v1prd/vol/ClearCase/cbnabi
cchome01.core.afcc.com:/export/home 282066944 52152264 82% 839861 34% /home/cchome01
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
grep: can't open
(Interrupt -- one more to kill letter)
And the script is here
+1 # think the hostname is available as the preset var HOSTNAME.
+2 # HOSTNM=`hostname`
+3 DATE=$(date +"%d-%b-%y %H:%M")
+4 SHORTNAME="FileSystem Mount"
+5 LONGNAME="Filesystem check"
+6 #I don't think grep supports |, just egrep.
+7 # You can also break apart really, really long lines with backslashes
+8 # so that it doesn't stretch your editor 3 miles wide.
+9 #checking filesystem if its mounted or not
+10 df -k |egrep '
+11 [/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|/dev/hd10opt|/dev/exportlv|/dev/optwarelv|/dev/orabinlv|/dev/ndmbinlv|/dev/oraclntlv|/dev/opts
wlv|/dev/cbnadlv|/dev/cbnabkplv|/dev/lvabinit1|/dev/lvappl|/dev/lveme|/dev/lvadmd1|/dev/lvserial|/dev/lvdata01|/dev/lvdata02|/dev/lvdata03|/dev/lvdata04|/dev
/lvmeta1|/dev/lvabini1|/dev/lvstage1|/dev/lvfeed1|/dev/lvstage2|/dev/lvcmmigr|/dev/lvbkdata1|/dev/lvbkdata2|/dev/lvbkdata3|/dev/lvbkdata4|/dev/lveers1| /dev/
expoptibmlv|/dev/expoptzloclv|/dev/performlv|/dev/sshcntllv|nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi|cchome01.core.afcc.com:/export/home]'>d.txt
+12
+13 # You can't just stick a file into []'s and expect it to work!
+14 # You're probably trying to check the return code of grep instead, right?
+15 # unfortunately, grep isn't going to work here since it'll return OK even if it
+16 # finds only ONE of these filesystems.
+17 #if [ d.txt == "1" ]
+18 #then
+19 #mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
+20 #else
+21 #mail -s "Filesystem check success $DATE HOSTNM " xx@domain.com
+22 #fi
+23 #exit
+24
+25 SUCCESS=0
+26 # Create a temp file with a secure random name.
+27 TMP=`mktemp`
+28 df -k >$TMP
+29 # Loop through each of these filesystems/paths individually.
+30 # if I knew AIX well enough I might try reading from /etc/fstab instead
+31 for DEV in /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
+32 /proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
+33 /dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
+34 /dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
+35 /dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
+36 /dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
+37 /dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
+38 /dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
+39 /dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
+40 /dev/expoptzloclv /dev/performlv/dev/sshcntllv\
+41 nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
+42 cchome01.core.afcc.com:/export/home
+43 do
+44 # Check if grep can find the device in the file. If not, set SUCCESS=1.
+45 # The -q flag tells grep to not print anything, all we need is the return code.
+46 grep -i "${DEV}" "${TMP}" || SUCCESS=1
+47 done
+48 # Delete the temp file.
+49 rm -f "$TMP"
+50
+51 if [ "${SUCCESS}" -eq 0 ]
+52 then
+53 mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
+54 else
+55 mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
+56 fi
I am attaching the script which is corrected as per your advice
km17590@cbnap001c[37]# vi gopalan
"gopalan" 57 lines, 2889 characters
+1 # think the hostname is available as the preset var HOSTNAME.
+2 # HOSTNM=`hostname`
+3 DATE=$(date +"%d-%b-%y %H:%M")
+4 SHORTNAME="FileSystem Mount"
+5 LONGNAME="Filesystem check"
+6 #I don't think grep supports |, just egrep.
+7 # You can also break apart really, really long lines with backslashes
+8 # so that it doesn't stretch your editor 3 miles wide.
+9 #checking filesystem if its mounted or not
+10 df -k |egrep '
+11 [/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|/dev/hd10opt|/dev/exportlv|/dev/optwarelv|/dev/orabinlv|/dev/ndmbinlv|/dev/oraclntlv|/dev/opts
wlv|/dev/cbnadlv|/dev/cbnabkplv|/dev/lvabinit1|/dev/lvappl|/dev/lveme|/dev/lvadmd1|/dev/lvserial|/dev/lvdata01|/dev/lvdata02|/dev/lvdata03|/dev/lvdata04|/dev
/lvmeta1|/dev/lvabini1|/dev/lvstage1|/dev/lvfeed1|/dev/lvstage2|/dev/lvcmmigr|/dev/lvbkdata1|/dev/lvbkdata2|/dev/lvbkdata3|/dev/lvbkdata4|/dev/lveers1| /dev/
expoptibmlv|/dev/expoptzloclv|/dev/performlv|/dev/sshcntllv|nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi|cchome01.core.afcc.com:/export/home]'>d.txt
+12
+13 # You can't just stick a file into []'s and expect it to work!
+14 # You're probably trying to check the return code of grep instead, right?
+15 # unfortunately, grep isn't going to work here since it'll return OK even if it
+16 # finds only ONE of these filesystems.
+17 #if [ d.txt == "1" ]
+18 #then
+19 #mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
+20 #else
+21 #mail -s "Filesystem check success $DATE HOSTNM " xx@domain.com
+22 #fi
+23 #exit
+24
+25 SUCCESS=0
+26 # Create a temp file with a secure random name.
+27 TMP=/tmp/$$
+28 df -k >$TMP
+29 # Loop through each of these filesystems/paths individually.
+30 # if I knew AIX well enough I might try reading from /etc/fstab instead
+31 for DEV in /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
+32 /proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
+33 /dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
+34 /dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
+35 /dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
+36 /dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
+37 /dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
+38 /dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
+39 /dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
+40 /dev/expoptzloclv /dev/performlv/dev/sshcntllv\
+41 nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
+42 cchome01.core.afcc.com:/export/home
+43 do
+44 # Check if grep can find the device in the file. If not, set SUCCESS=1.
+45 # The -q flag tells grep to not print anything, all we need is the return code.
+46 grep -i "${DEV}" "${TMP}" || SUCCESS=1
+47 done
+48 # Delete the temp file.
+49 rm -f "$TMP"
+50
+51 if [ "${SUCCESS}" -eq 0 ]
+52 then
+53 mail -s "Filesystem check success $DATE $HOSTNAME" xx@domain.com
+54 else
+55 mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" xx@domain.com
+56 fi
+57 exit
# think the hostname is available as the preset var HOSTNAME.
{
[ "$_debug" == "on" ] && $@
}
debug set -x
# HOSTNM=`hostname`
DATE=$(date +"%d-%b-%y %H:%M")
SHORTNAME="FileSystem Mount"
LONGNAME="Filesystem check"
#I don't think grep supports |, just egrep.
# You can also break apart really, really long lines with backslashes
# so that it doesn't stretch your editor 3 miles wide.
#checking filesystem if its mounted or not
#df -k |egrep '
#[/dev/hd4|/dev/hd2|/dev/hd9var|/dev/hd3|/dev/hd1|/proc|/dev/hd10opt|/dev/exportlv|/dev/optwarelv|/dev/orabinlv|/dev/ndmbinlv|/dev/oraclntlv|/dev/optswlv|/dev/cbnadlv|/dev/cbnabkplv|/dev/lvabinit1|/dev/lvappl|/dev/lveme|/dev/lvadmd1|/dev/lvserial|/dev/lvdata01|/dev/lvdata02|/dev/lvdata03|/dev/lvdata04|/dev/lvmeta1|/dev/lvabini1|/dev/lvstage1|/dev/lvfeed1|/dev/lvstage2|/dev/lvcmmigr|/dev/lvbkdata1|/dev/lvbkdata2|/dev/lvbkdata3|/dev/lvbkdata4|/dev/lveers1| /dev/expoptibmlv|/dev/expoptzloclv|/dev/performlv|/dev/sshcntllv|nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi|cchome01.core.afcc.com:/export/home]'>d.txt
# You can't just stick a file into []'s and expect it to work!
# You're probably trying to check the return code of grep instead, right?
# unfortunately, grep isn't going to work here since it'll return OK even if it
# finds only ONE of these filesystems.
#if [ d.txt == "1" ]
#then
#mail -s "Filesystem check pls inestigate "$DATE" "$HOSTNM" xx@domain.com
#else
#mail -s "Filesystem check success $DATE HOSTNM " xx@domain.com
#fi
#exit
SUCCESS=0
# Create a temp file with a secure random name.
TMP=/tmp/$$
df -k >$TMP
# Loop through each of these filesystems/paths individually.
# if I knew AIX well enough I might try reading from /etc/fstab instead
for DEV in /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
/proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
/dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
/dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
/dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
/dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
/dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
/dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
/dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
/dev/expoptzloclv /dev/performlv/dev/sshcntllv\
nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
cchome01.core.afcc.com:/export/home
do
# Check if grep can find the device in the file. If not, set SUCCESS=1.
# The -q flag tells grep to not print anything, all we need is the return code.
grep -i "${DEV}" "${TMP}" || SUCCESS=1
done
# Delete the temp file.
rm -f "$TMP"
if [ "${SUCCESS}" -eq 0 ]
then
mail -s "Filesystem check success $DATE $HOSTNAME" kiran.kumar.mundiyath@citi.com
#DEBUG set +x
else
mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" kiran.kumar.mundiyath@citi.com
fi
#exit
---------- Post updated at 04:16 PM ---------- Previous update was at 04:14 PM ----------
[/COLOR]Pls adice and request you to crop the script and pls give me
#!/bin/ksh
SUCCESS=0
# Create a temp file with a secure random name.
TMP=/tmp/$$
df -k >$TMP
# Loop through each of these filesystems/paths individually.
# if I knew AIX well enough I might try reading from /etc/fstab instead
for DEV in /dev/hd4 /dev/hd2 /dev/hd9var /dev/hd3 /dev/hd1 \
/proc /dev/hd10opt /dev/exportlv /dev/optwarelv \
/dev/orabinlv/dev/ndmbinlv /dev/oraclntlv /dev/optswlv \
/dev/cbnadlv /dev/cbnabkplv /dev/lvabinit1 /dev/lvappl \
/dev/lveme /dev/lvadmd1 /dev/lvserial /dev/lvdata01 \
/dev/lvdata02 /dev/lvdata03 /dev/lvdata04 /dev/lvmeta1 \
/dev/lvabini1 /dev/lvstage1 /dev/lvfeed1 /dev/lvstage2 \
/dev/lvcmmigr /dev/lvbkdata1 /dev/lvbkdata2 /dev/lvbkdata3 \
/dev/lvbkdata4 /dev/lveers1 /dev/expoptibmlv \
/dev/expoptzloclv /dev/performlv/dev/sshcntllv\
nasswd10v1prd.nam.nsroot.net:/vol/ClearCase/cbnabi \
cchome01.core.afcc.com:/export/home
do
# Check if grep can find the device in the file. If not, set SUCCESS=1.
# The -q flag tells grep to not print anything, all we need is the return code.
grep -q -i "${DEV}" "${TMP}" || SUCCESS=1
done
# Delete the temp file.
rm -f "$TMP"
if [ "${SUCCESS}" -eq 0 ]
then
mail -s "Filesystem check success $DATE $HOSTNAME" kiran.kumar.mundiyath@citi.com
else
mail -s "Filesystem check pls inestigate $DATE $HOSTNAME" kiran.kumar.mundiyath@citi.com
fi
I did add -q to grep, but that's just an aesthetic fix, it'll spam less. Are you sure it's not freezing on mail?