Linux中shell脚本案例(二)
下面是案例: 1、ping测试IP地址 代码:
1 2 3 4 5 6 |
#!/bin/bash for i in 1 2 3 4 do echo "the number of $i computer is " ping -c 1 192.168.0.$i done |
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
the number of 1 computer is PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data. --- 192.168.0.1 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 10000ms the number of 2 computer is PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data. --- 192.168.0.2 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 10000ms the number of 3 computer is PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data. --- 192.168.0.3 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 10000ms the number of 4 computer is PING 192.168.0.4 (192.168.0.4) 56(84) bytes of data. --- 192.168.0.4 ping statistics --- 1 packets transmitted, 0 received, 100% packet loss, time 10000ms |
2、打印…
Read more