linux - Bash Script to loop through list to check server status -


i'm trying create script ping amongst other things, remote servers held in list.

this have have, keep getting error:

./monitor_sats.sh: cannot make pipe command substitution: many open files.

this code, helping.

 #!/bin/bash    function ping {     in `cat server_list`         ping -c1 ${i} > /dev/null        if [ ${?} -eq 0 ];          echo "$(tput setaf 2)on$(tput sgr0)"      else         echo "$(tput setaf 1)off$(tput sgr0)"      fi    done }     echo "amsterdam - server  $(ping) "  echo "hong kong - server  $(ping) "  echo "london    - server  $(ping) "  echo "singapore - server  $(ping) " 

change function name below;

#!/bin/bash function pingtoserver {   in `cat server_list`        ping -c1 ${i} > /dev/null        if [ ${?} -eq 0 ];          echo "$(tput setaf 2)on$(tput sgr0)"      else         echo "$(tput setaf 1)off$(tput sgr0)"      fi    done }   echo "amsterdam - server  $(pingtoserver) "  echo "hong kong - server  $(pingtoserver) "  echo "london    - server  $(pingtoserver) "  echo "singapore - server  $(pingtoserver) " 

you can use this;

#!/bin/bash countries=("amsterdam" "hong kong" "london" "singapore") counter=0 cat server_list | while read server;   ping -c1 ${server} > /dev/null  if [ ${?} -eq 0 ];          echo "${countries[$counter]} - server- $(tput setaf 2)on$(tput sgr0)"      else          echo "${countries[$counter]} - server-$(tput setaf 1)off$(tput sgr0)"      fi     counter=$(($counter+1)) done 

Comments

Popular posts from this blog

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -