Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- pid=$(pgrep sipbx)
- uptime=$(ps -p "$pid" -o etime=)
- process=$(ps -ef | grep -i sipbx | grep -v grep)
- disk_mount=$(df -h | grep nsfs | awk '{print $5}' | tr -d '%')
- dick=$(df -h| head -2 | tail -1| awk '{print $5}' | tr -d '%')
- disk_email=$(df -h | grep nsfs)
- hostname=$(hostname | cut -d. -f1)
- email="cstobie@esi-estech.com, pvazquez@esi-estech.com, davidthompson@esi-estech.com, vchan@esi-estech.com"
- status=$(service netsapiens-nms status)
- 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"
- 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"
- 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"
- nsfs=('nysas1' 'lasas1' 'nysas2' 'lasas2' 'nyvth' 'lavth')
- mount=('nms-22' 'nms-21' 'nms-01' 'nms-02')
- for i in "${nsfs[@]}"
- do
- if [[ $hostname == $i ]]
- then
- if [[ ! $pid ]]
- then
- if [[ $disk -le 85 ]]
- then
- /etc/init.d/netsapiens_nms start
- if [[ $pid ]]
- then
- echo -e $success | mail -s "SiPbx successful restart on $hostname" $email
- else
- echo -e $failure | mail -s "Sipbx failed restart on $hostname" $email
- fi
- else
- echo -e $disk_fail | mail -s "Disk usage was too high on $hostname to restart SiPbx" $email
- fi
- fi
- fi
- done
- for i in "${mount[@]}"
- do
- if [[ $hostname == $i ]]
- then
- if [[ ! $pid ]]
- then
- if [[ $mount -le 85 ]]
- then
- /etc/init.d/netsapiens_nms start
- if [[ $pid ]]
- then
- echo -e $success | mail -s "SiPbx successful restart on $hostname" $email
- else
- echo -e $failure | mail -s "Sipbx failed restart on $hostname" $email
- fi
- else
- echo -e $disk_fail | mail -s "Disk usage was too high on $hostname to restart SiPbx" $email
- fi
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement