Well i have some questions / suggestions that may help lead you in the right direction:
1. Do you use a non-standard copy / version of ping? I ask this as the following line:
Code:
nfs=`ping teslltidcnas01`
Hangs any script I have it in as ping has not been told to finish.
2. The prolific use of cat and grep with awk are not required:
Code:
df -h | grep nas|awk '{print $6}' > $df_file
# becomes
df -h | awk '/nas/{print $6}' > $df_file
fs_share=`cat /etc/vfstab|grep nas|grep -v "#"|awk '{print $3}'`
# becomes
fs_share=`awk '/nas/ && !/^#/{print $3}' /etc/vfstab`
Also here you will see I added '^' which means that we do not wish to see lines that are completely commented. This is different to 'grep -v "#"' or '!/#/'
as the last examples would get rid of something in the following format:
Code:
blah ablha blah # This is a comment
3. To make the code easier to read and to save you headaches later on with nesting, I would recommend the use of $() over ``
4. Instead of using : so that your 'if' has somewhere to go, you can negate the result using !:
Code:
if [ -f $tmp ];then
:
else
cat /dev/null > $tmp
fi
# becomes
if [ ! -f $tmp ]; then
cat /dev/null > $tmp
fi
This cat could also be simplified:
5. Not sure if this one is a personal choice, but there is no need to use a different file descriptor in your while loop
6. Instead of using 'wc -l' to get a count, change the while loop to use a counter:
Code:
#example
counter=0
(( counter++ ))
echo $counter
7. I am not sure the following function is exactly what you were looking for (or at least it is a bit vague):
Code:
chk_file ()
{
for shr in `cat $tmp`; do
if [ -e "$shr/$test" ]; then
cf_rc=0
else
cf_rc=1
fi
done
}
Based on the test you use later:
Code:
if [ "$rc" -eq "0" ]; then
chk_file
if [ "$cf_rc" -eq "0" ]; then
echo " INFO: All file access test(s) successful"
rc=0
else
echo " ERROR: Cannot acccess one or more test file"
rc=1
fi
fi
Assuming we get in to run chk_file, as long as the last entry in $tmp has the require file (DO_NOT_DELETE) you will always see:
Code:
INFO: All file access test(s) successful
Which is not necessarily the case if the first entry in the $tmp file does not have the required file
8. You perform many numeric comparisons but do not use the associated arithmetic operators:
Code:
if [ "$na_rc" -eq "0" ]; then
# becomes
if (( na_rc == 0 )); then
# or if you change the if / else structure
if (( na_rc )); then
I suggest testing this in an alternate small script to understand how it works.
9. Lastly, you finish the script with 'return' which is used to return the status of a function whereas 'exit' should be used at the end of a script (or anywhere in between as well)
Let me know how you go with all the information and I will see if I can help further with your actual query.