Shell Programming Examples

From RoggeWiki
Revision as of 10:01, 22 September 2011 by Tom (talk | contribs)
Jump to navigation Jump to search

Ping all hosts in a subnet

subnet=”141.93.169 i=1 while [ $i -lt 255 ] do

  ping ${subnet}.${i} 2 1>/dev/null 2>&1
  if [ $? -ne 0 ] ; then
     echo "${subnet}.${i},down"
  else echo "${subnet}.${i},up"
  fi
  i=$(expr $i + 1 )

done