等待网络接口执行命令前 [英] Wait for Network Interface Before Executing Command
问题描述
我有我会如何实现这一目标一对夫妇的想法。不知道怎么会有我的脚本了。
I have a couple ideas on how I would achieve this. Not sure how I would script it.
方法1:(可能是更好的选择)
Method 1: (probably the better choice)
创建一个循环,直到回复收到然后执行命令ping请求的服务器
如果在时间x量仍没有收到回复/继续运行脚本。
Create a loop that pings a server until reply is received then execute command if no reply is received in X amount of time/runs continue script.
方法2:
检查,如果网络接口具有有效的IP,然后继续脚本
Check if network interface has valid IP then continue script
人会如何着手在脚本中添加此功能。将在awk或者grep的是使用在这样的情况呢?预先感谢您的任何输入。
How would one go about adding this functionality in a script. Would awk or grep be of use in a situation like this? Thank you in advance for ANY input.
推荐答案
这个命令应该等待,直到它可以与谷歌或已尝试50次:
This command should wait until it can contact google or it has tried 50 times:
for i in {1..50}; do ping -c1 www.google.com &> /dev/null && break; done
的为我在{1..50}
循环50次,或直至破
被执行。在平-C1 www.google.com
1发送Ping报文谷歌和&放大器;>的/ dev / null的
重定向所有的输出为null,所以没有什么是所输出的。 &放大器;&安培;突破
执行只有previous命令成功完成破发,所以当平
是成功的循环才会结束。
The for i in {1..50}
loops 50 times or until a break
is executed. The ping -c1 www.google.com
sends 1 ping packet to google, and &> /dev/null
redirects all the output to null, so nothing is outputed. && break
executes break only if the previous command finished successfully, so the loop will end when ping
is successful.
这篇关于等待网络接口执行命令前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!