Shell Programming Examples

From RoggeWiki
Revision as of 10:00, 22 September 2011 by Tom (talk | contribs) (Created page with '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}.$…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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