Advertisement
Jerownimow

core_check.sh

Apr 12th, 2018
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.79 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. #Variable storage
  4. core_env=$("DV")
  5. core_dir1=$(printf "/home/essbase/TWSEssbRuns/9.6.1/server/bin")
  6. core_dir2=$(printf "/home/essbase/TWSEssbRuns/9.6.1/tomcat/bin")
  7.  
  8. #Check core file on the 1st dir
  9. cd $core_dir1
  10.  
  11. core_out_count1=$(find . -maxdepth 1 -type f -name "core.*" -printf "\n" | wc -l)       #count on dir1
  12. core_check1= $(find . -type f -name 'core.*' -exec sh -c '                             
  13.                 for name; do
  14.                     if strings "$name" | grep -qF "pmdtm("; then
  15.                         printf "%s\n" "$name"
  16.                     fi
  17.                 done' find-sh {} + | awk '{print $0,"\n"}')                             #initial check of core files
  18. core_check2=$(find . -type f -name 'core.*' -exec file {} + | awk '{print $0,"\n"}')    #check for the core files if core_check1 returns blank
  19.  
  20. if [$core_out_count1!=0];
  21.     if [$core_check1=" "];
  22.         if [$core_check1!=" "];
  23.             then core_msg1=$(echo "$core_out_count2 core files exist in $core_dir2.")
  24.         fi
  25.     fi   
  26. elif core_msg1=$(echo "No core files in $core_dir1.")
  27. fi
  28.      
  29. #Check core file on the 2nd dir
  30. cd $core_dir2
  31.  
  32. core_out_count2=$(find . -maxdepth 1 -type f -name "core.*" -printf "\n" | wc -l)       #count on dir2
  33. core_check1= $(find . -type f -name 'core.*' -exec sh -c '
  34.                 for name; do
  35.                     if strings "$name" | grep -qF "pmdtm("; then
  36.                         printf "%s\n" "$name"
  37.                     fi
  38.                 done' find-sh {} + | awk '{print $0,"\n"}')                             #initial check of core files
  39. core_check2=$(find . -type f -name 'core.*' -exec file {} + | awk '{print $0,"\n"}')    #check for the core files if core_check1 returns blank
  40.  
  41. if [$core_out_count2!=0];
  42.     if [$core_check1=" "];
  43.         if [$core_check2!=" "];
  44.             then core_msg2=$(echo "$core_out_count2 core files exist in $core_dir2.")
  45.         fi
  46.     fi 
  47. elif core_msg2=$(echo "No core files in $core_dir2.")
  48. fi
  49.  
  50. #Send e-mail to users
  51. if [$core_out_count1!=0 && $core_check1!=" "];                                          #core in dir1 exist & 1st check script worked
  52.     then echo "$core_msg1\n\n$core_check1" | mail -s "Core files exist in $core_env" "[email protected],[email protected],[email protected]"
  53.         if [$core_out_count2!=0 && $core_check1!=" "];                                  #core in dir2 exist & 1st check script worked
  54.             then echo "$core_msg2\n\n$core_check1" | mail -s "Core files exist in $core_env" "[email protected],[email protected],[email protected]"
  55.                 if [$core_out_count1!=0 && $core_check2!=" "];                          #core in dir1 exist & 1st check script did not worked
  56.                     then echo "$core_msg1\n\n$core_check2" | mail -s "Core files exist in $core_env" "[email protected],[email protected],[email protected]"
  57.                         if [$core_out_count2!=0 && $core_check2!=" "];                  #core in dir2 exist & 1st check script did not worked
  58.                             then echo "$core_msg2\n\n$core_check2" | mail -s "Core files exist in $core_env" "[email protected],[email protected],[email protected]"
  59.                         fi
  60.                 fi
  61.         fi
  62.     fi
  63.  
  64. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement