
rayTX
New User
Dec 21, 2012, 7:40 AM
Post #1 of 3
(2878 views)
|
Script hanging due to unresponsive server
|
Can't Post
|
|
Hello, I was hoping for some help with this script I am trying to get working. Basically I want the script to first ping my servers, and if the response is "no" then i want to skip that one and continue the loop. Currently what happens is it gets to one server that is offline, and it will not skip it. I have tried a few different ways around this, but here is my current code:
$cas = 31; while ($cas++ <=58) { $ping = `ping cas$cas| awk '{print \$1}'`; print "ping test=$ping\n"; if ($ping eq "no") { next; } } continue { if ($ping ne "no") { # This gets hostname from each server ($shostname, $nl) = split(/\n/, `ssh cas$cas "hostname"`); # This will get the CPU Utilzation ($mpstat, $nl) = split(/\n/, `ssh cas$cas "/usr/bin/mpstat | grep -A 5 "%idle" | tail -1"`); ($a,$b,$c,$d,$e,$f,$g,$h,$cpu) = split(/\s+/,$mpstat); $cputil = 100 - $cpu; $cputil1 = sprintf "%.2f", $cputil; #print "$cputil1 \n"; # This uses the uptime command to get the load average ($uptime, $nl) = split(/\n/, `ssh cas$cas "uptime"`); ($a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$load) = split(/\s+/,$uptime); ($loadavg, $nl) = split(/\,/, $load); #print "$loadavg \n"; # This uses the free command to get used and total memory and calculate the utilization ($free, $nl) = split(/\n/, `ssh cas$cas "free -tm"|grep Total`); ($a,$total,$used,$free) = split(/\s+/,$free); $mem = ($used / $total) * 100; $memutil = sprintf "%.2f", $mem; #print "$memutil \n"; print "$shostname,$cputil1,$loadavg,$memutil\n"; } } #continue #{ # $cas++; #}; print "done \n"; Any suggestions are welcome, I feel like I might be close to getting it to work, but I just am missing something.
|