[英]Ping with a variable in linux script
I want that my script pings the ip-addresses 192.168.0.45 192.168.0.17 192.168.0.108 by doing this: 我想通过这样做我的脚本ping IP地址192.168.0.45 192.168.0.17 192.168.0.108:
bash Script.sh 45 17 108
I want to give the last numbers with bash to ping this ip-addresses. 我想用bash给最后一个数字来ping这个ip-addresses。
I don't know how I have to do this. 我不知道我该怎么做。 Do I have to work with a 'case' in a do while or something else?? 我是否必须在做某事或其他事情的情况下使用'案例'?
#!/bin/bash
for i in $*; do
ping 192.168.0.$i
done
I want to give the last numbers with bash to ping this ip-addresses. 我想用bash给最后一个数字来ping这个ip-addresses。
I presume, you want to ping the addresses simultaneously. 我认为,你想同时ping地址。 In that case you can do this: 在这种情况下,你可以这样做:
Script.sh: Script.sh:
#!/bin/bash
ping 192.168.0.$1 & ping 192.168.0.$2 & ping 192.168.0.$3 &
This will send all of the three ping commands to background where they will be executed simultaneously and print continuous output on terminal. 这将把所有三个ping命令发送到后台,同时执行它们并在终端上打印连续输出。
You can do this with a for loop too: 您也可以使用for循环执行此操作:
#!/bin/bash
for i in $*;do
ping 192.168.0.$i &
done
The for loop method can take any number of arguments for循环方法可以使用任意数量的参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.