One with bash, one with standard Bourne shell:
Bash script | Bourne script
The scripts loop through, doing an nmap scan against a Class C (/24) subnet, polling 5 hosts at a time, saving the results to an individual file, and waiting until all five have completed before moving on to the next five IP addresses. It has a special case telling it not to bother polling .255, the broadcast address.
#!/bin/bash | #!/bin/sh for round in `seq 0 50` | export round=0 > while [ "$round" -le "50" ] do do echo "`date`: Starting round $round" echo "`date`: Starting round $round" for offset in `seq 1 5` | export offset=1 > while [ "$offset" -le "5" ] do do let octet=offset+5*round | octet=`expr $round \* 5` | octet=`expr $octet + $offset` [ "$octet" != "255" ] && \ [ "$octet" != "255" ] && \ nmap -P0 -O 192.168.196.$octet > ${octet}.nmap 2>&1 & nmap -P0 -O 192.168.196.$octet > ${octet}.nmap 2>&1 & > offset=`expr $offset + 1` done done echo "`date`: Waiting for round $round" echo "`date`: Waiting for round $round" wait wait > round=`expr $round + 1` done done
Note on sdiff: The ">" in the middle show where the /bin/sh script has an extra line that the /bin/bash script doesn't need. The "|" in the middle highlights where a line is different. No symbol in the middle indicates that the two lines are the same.