Basic examples of Bash Scripting
Goal Ping Sweep a range, generate a list of hosts that respond to ICMP Echo request with a reply
Format: Explanation of command + arguments
ping on a count (-c) of 1
Grep = show only quoted string
Cutting a delimiter (-d) specified in " " - in this case space
The field specifies the word (in this case the IP address so the flag yields a list of live hosts) of 4.
A range can be specified if 4-9 format is used
Sed is used to remove characters from final output 's/.$//' ***Research pending on the syntax of "sed" linux command ***
Example Command
For loop - don't forget to add "; done" at the end so we don't run into '>' prompt issue
Below for loop: pings 1-255 hosts in 192.168.1.0/24
Grep prints the matching lines "64 bytes from"
Cut - remove sections from each #line of files using "-d".
--delimiter=DELIM - use delimiter instead of TAB for field delimiter. (in this case a space " ")
Sed - stream editor for filtering and transforming text helps us (more research needed on 's/.$//')
My Traceroute - mtr
-r for outputing the results on the terminal
--no-dns does not resolve hostnames
My traceroute and PING test - && executes command to the right of && after command to the left of && has been completed
In this case, mtr is executed, once it finishes for loop is executed
For loop + mtr - For i in range 160-190 runs a mytraceroute to specified #X.X.X.$i IP address (no DNS resolution flag)
Grep prints #the lines that #contain a "." (such as #ones with dotted decimal IP addresses)
Cut -d uses #space as delimiter ; done completes the #loop.
Useful for checking routing path in a whole subnet in dual homed networks with different egress and ingress paths
But... How to save test results to a file? Add > after command followed by the filename (thanks to @nin)
Use the ping command to obtain the IP address of the specified website
Last updated