Bash loop: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
|  (Created page with "<pre> #!/bin/bash  _admin_ip="202.54.1.33|MUM_VPN_GATEWAY 23.1.2.3|DEL_VPN_GATEWAY 13.1.2.3|SG_VPN_GATEWAY" for e in $_admin_ip do    echo  allow from "${e%%|*}" to any port 2...") | mNo edit summary | ||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| <metadesc>Basic bash looping examples</metadesc> | |||
| == Interesting Loop == | |||
| <pre> | <pre> | ||
| #!/bin/bash | #!/bin/bash | ||
| _admin_ip="202.54.1.33|MUM_VPN_GATEWAY 23.1.2.3|DEL_VPN_GATEWAY 13.1.2.3|SG_VPN_GATEWAY" | _admin_ip="202.54.1.33|MUM_VPN_GATEWAY 23.1.2.3|DEL_VPN_GATEWAY 13.1.2.3|SG_VPN_GATEWAY" | ||
| for e in $_admin_ip | for e in $_admin_ip | ||
| Line 7: | Line 9: | ||
|     echo  allow from "${e%%|*}" to any port 22 proto tcp comment "Open SSH port for ${e##*|}" |     echo  allow from "${e%%|*}" to any port 22 proto tcp comment "Open SSH port for ${e##*|}" | ||
| done | done | ||
| </pre> | |||
| <pre>  | |||
| ./interesting_loop.sh   | |||
| allow from 202.54.1.33 to any port 22 proto tcp comment Open SSH port for MUM_VPN_GATEWAY | allow from 202.54.1.33 to any port 22 proto tcp comment Open SSH port for MUM_VPN_GATEWAY | ||
| allow from 23.1.2.3 to any port 22 proto tcp comment Open SSH port for DEL_VPN_GATEWAY | allow from 23.1.2.3 to any port 22 proto tcp comment Open SSH port for DEL_VPN_GATEWAY | ||
| allow from 13.1.2.3 to any port 22 proto tcp comment Open SSH port for SG_VPN_GATEWAY | allow from 13.1.2.3 to any port 22 proto tcp comment Open SSH port for SG_VPN_GATEWAY | ||
| </pre> | </pre> | ||
| [[Category:Bash]] | [[Category:Bash]] | ||
Latest revision as of 14:59, 25 April 2024
Interesting Loop
#!/bin/bash
_admin_ip="202.54.1.33|MUM_VPN_GATEWAY 23.1.2.3|DEL_VPN_GATEWAY 13.1.2.3|SG_VPN_GATEWAY"
for e in $_admin_ip
do
   echo  allow from "${e%%|*}" to any port 22 proto tcp comment "Open SSH port for ${e##*|}"
done
./interesting_loop.sh allow from 202.54.1.33 to any port 22 proto tcp comment Open SSH port for MUM_VPN_GATEWAY allow from 23.1.2.3 to any port 22 proto tcp comment Open SSH port for DEL_VPN_GATEWAY allow from 13.1.2.3 to any port 22 proto tcp comment Open SSH port for SG_VPN_GATEWAY