#!/bin/ksh
#
# XARY aka Andrei.Ryjov@spasu.net       Tue Dec 23 12:16:15 CET 2008
#
# check if "df" command on AIX gives "permission" on stdin
#
uname -s | egrep -s AIX || exit 0       # Run on AIX only

MESSAGE=`df -g 2>&1 | egrep 'permission|does not exist.'`

[ `echo "$MESSAGE" | wc -w` -lt 1 ] && exit 0

printf "Broken CIFS mount(s)\n\n$MESSAGE\n"

printf "\nNot Remounting ...\n"

exit 1 # Otherwise the LPAR may panic on CIFS remount

printf "\nRemounting ...\n"

ps -eflo args | awk '$1~/mount$/' | grep mount && { printf "Another remount in progress - giving up\n"; exit 1; }


MOUNTS=`mount | awk '$4=="cifs" {print $3}'`
AddSleep=0


for i in $MOUNTS; do
  F=$i/.nagios_test
  echo hello >$F && rm $F && continue
  printf "\nProblem on $i - remounting\n"


  printf "\nNot remounting now - it may crash the server!\n"; continue  # Re-enable again by XARY un 22 10:25:34 CEST 2009



  (

     umount $i >/dev/null 2>&1
     sleep 5
     umount $i >/dev/null 2>&1
     sleep 2
     mount | awk '$3=="'$i'" {print $3}' | egrep -s $i || mount $i

  ) &

  sleep 5

  AddSleep=`expr $AddSleep + 10`

done

sleep $AddSleep # if we would nohup the background remount, the we would loose the output from it

exit 1

