Jot: often forgotten jem

From FBSD_tips

Jump to: navigation, search

Contents

[edit] Rationale

Many times you want to do something in a sequence or even randomly with a boundary, for these (and surprisingly many other) uses, jot is your tool!

[edit] Uses

[edit] Ping a series of hosts

jot 255 1 255 will print 255 increments starting at 1 and ending at 255, so if you wanted to ping a series of hosts and announce which are accessable you might do something like :

for CT in `jot 255 1 255`
do 
 ping -c 1 10.9.8.${CT} > /dev/null 
 if [ $? -eq 0 ]
 then
  echo "10.9.8.${CT} is alive"
 fi
done

You could make this a lot shorter, I was verbose in the interests of demonstration, this command is equivalent :

for CT in `jot 3 1 3`;  do    ping -c 1 10.200.1.${CT} > /dev/null &&  echo "10.200.1.${CT} is alive" ; done

[edit] Discussion

Personal tools