Advertisement
Guest User

Untitled

a guest
Nov 16th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.42 KB | None | 0 0
  1. #!/bin/bash
  2. pid=$(pgrep sipbx)
  3. uptime=$(ps -p "$pid" -o etime=)
  4. process=$(ps -ef | grep -i sipbx | grep -v grep)
  5. disk_mount=$(df -h | grep nsfs | awk '{print $5}' | tr -d '%')
  6. dick=$(df -h| head -2 | tail -1| awk '{print $5}' | tr -d '%')
  7. disk_email=$(df -h | grep nsfs)
  8. hostname=$(hostname | cut -d. -f1)
  9. email="cstobie@esi-estech.com, pvazquez@esi-estech.com, davidthompson@esi-estech.com, vchan@esi-estech.com"
  10. status=$(service netsapiens-nms status)
  11. success="The Disk usage on $hostname was low enough to safely restart the SiPbx service.\n Please investigate this issue to ensure that everything is up and running as expected\n The current pid of the newly started process is $pid.\n The uptime is $uptime.\n\n Process verification: \n\n Output of pgrep: $pid \n\n Output of ps: $process \n\n Service state: $status"
  12. failure="The process SiPbx will not start. \n\nOutput of pgrep: $pid \n\nOutput of ps: $process \n\n Service state: $status \n\n Please investigate on $hostname to determine root cause"
  13. disk_fail="The disk usage on $hostname was too high to safely restart the SiPbx service. \n Please investigate disk issues and restart the service manually. \n\n Disk Usage: $disk_email"
  14. nsfs=('nysas1' 'lasas1' 'nysas2' 'lasas2' 'nyvth' 'lavth')
  15. mount=('nms-22' 'nms-21' 'nms-01' 'nms-02')
  16.  
  17.  
  18. for i in "${nsfs[@]}"
  19.  do
  20.   if [[ $hostname == $i ]]
  21.       then
  22.     if [[ ! $pid ]]
  23.      then
  24.        if [[ $disk -le 85 ]]
  25.         then
  26.          /etc/init.d/netsapiens_nms start
  27.           if [[ $pid ]]
  28.            then
  29.         echo -e $success | mail -s "SiPbx successful restart on $hostname" $email
  30.            else
  31.         echo -e $failure | mail -s "Sipbx failed restart on $hostname" $email
  32.           fi
  33.         else
  34.          echo -e $disk_fail | mail -s "Disk usage was too high on $hostname to restart SiPbx" $email
  35.        fi
  36.     fi
  37.  fi
  38. done
  39.  
  40. for i in "${mount[@]}"
  41.  do
  42.     if [[ $hostname == $i ]]
  43.       then
  44.         if [[ ! $pid ]]
  45.          then
  46.            if [[ $mount -le 85 ]]
  47.             then
  48.              /etc/init.d/netsapiens_nms start
  49.               if [[ $pid ]]
  50.                then
  51.                 echo -e $success | mail -s "SiPbx successful restart on $hostname" $email
  52.                else
  53.                 echo -e $failure | mail -s "Sipbx failed restart on $hostname" $email
  54.               fi
  55.             else
  56.              echo -e $disk_fail | mail -s "Disk usage was too high on $hostname to restart SiPbx" $email
  57.            fi
  58.         fi
  59.   fi
  60. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement