{"type":"rich","version":"1.0","provider_name":"phorkie","provider_url":"https:\/\/p.cweiske.de\/","title":"pingwait  - wait until a host is online and pingable","author_name":"Christian Weiske","cache_age":86400,"width":900,"height":900,"html":"<!-- embedding all files of https:\/\/p.cweiske.de\/941 -->\n<link rel=\"stylesheet\" href=\"https:\/\/p.cweiske.de\/css\/embed.css\"\/>\n<div class=\"phork\" id=\"941\">\n    <div class=\"phork-file\">\n <div class=\"phork-content\">\n  <style type=\"text\/css\">\/**\n * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2014 Benny Baumann\n * (http:\/\/qbnz.com\/highlighter\/ and http:\/\/geshi.org\/)\n *\/\n.bash .de1, .bash .de2 {font: normal normal 1em\/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}\n.bash  {font-family:monospace;}\n.bash .imp {font-weight: bold; color: red;}\n.bash li, .bash .li1 {color: #DDD;}\n.bash .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}\n.bash .kw1 {color: #000000; font-weight: bold;}\n.bash .kw2 {color: #c20cb9; font-weight: bold;}\n.bash .kw3 {color: #7a0874; font-weight: bold;}\n.bash .co0 {color: #666666; font-style: italic;}\n.bash .co1 {color: #800000;}\n.bash .co2 {color: #cc0000; font-style: italic;}\n.bash .co3 {color: #000000; font-weight: bold;}\n.bash .co4 {color: #666666;}\n.bash .es1 {color: #000099; font-weight: bold;}\n.bash .es2 {color: #007800;}\n.bash .es3 {color: #007800;}\n.bash .es4 {color: #007800;}\n.bash .es5 {color: #780078;}\n.bash .es_h {color: #000099; font-weight: bold;}\n.bash .br0 {color: #7a0874; font-weight: bold;}\n.bash .sy0 {color: #000000; font-weight: bold;}\n.bash .st0 {color: #ff0000;}\n.bash .st_h {color: #ff0000;}\n.bash .nu0 {color: #000000;}\n.bash .re0 {color: #007800;}\n.bash .re1 {color: #007800;}\n.bash .re2 {color: #007800;}\n.bash .re4 {color: #007800;}\n.bash .re5 {color: #660033;}\n.bash span.xtra { display:block; }\n<\/style><div class=\"code\"><table class=\"bash\"><tbody><tr class=\"li1\"><td class=\"ln\"><pre class=\"de1\">1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n<\/pre><\/td><td class=\"de1\"><pre class=\"de1\"><span class=\"co0\">#!\/bin\/bash<\/span>\n<span class=\"co0\"># wait until a host is pingable, then exit<\/span>\n&#160;\n<span class=\"re2\">ping_cancelled<\/span>=<span class=\"kw2\">false<\/span> &#160; &#160;<span class=\"co0\"># Keep track of whether the loop was cancelled, or succeeded<\/span>\n<span class=\"kw1\">until<\/span> <span class=\"kw2\">ping<\/span> <span class=\"re5\">-c1<\/span> <span class=\"st0\">&quot;$1&quot;<\/span> <span class=\"sy0\">&gt;\/<\/span>dev<span class=\"sy0\">\/<\/span>null <span class=\"nu0\">2<\/span><span class=\"sy0\">&gt;&amp;<\/span><span class=\"nu0\">1<\/span>; <span class=\"kw1\">do<\/span> :; <span class=\"kw1\">done<\/span> <span class=\"sy0\">&amp;<\/span> &#160; &#160;<span class=\"co0\"># The &quot;&amp;&quot; backgrounds it<\/span>\n<span class=\"kw3\">trap<\/span> <span class=\"st0\">&quot;kill $!; ping_cancelled=true&quot;<\/span> SIGINT\n<span class=\"kw3\">wait<\/span> <span class=\"re4\">$!<\/span> &#160; &#160; &#160; &#160; &#160;<span class=\"co0\"># Wait for the loop to exit, one way or another<\/span>\n<span class=\"kw3\">trap<\/span> - SIGINT &#160; &#160;<span class=\"co0\"># Remove the trap, now we're done with it<\/span>\n<span class=\"kw3\">echo<\/span> <span class=\"st0\">&quot;Done pinging, cancelled=<span class=\"es2\">$ping_cancelled<\/span>&quot;<\/span>\n&#160;<\/pre><\/td><\/tr><\/tbody><\/table><\/div>\n <\/div>\n <div class=\"phork-meta\">\n  <a href=\"https:\/\/p.cweiske.de\/941\/rev-raw\/0c165c4126f7bc10dd2177bd9f2400c019428efd\/pingwait.sh\" style=\"float: right\">view raw source<\/a>\n  <a href=\"https:\/\/p.cweiske.de\/941#pingwait.sh\">pingwait.sh<\/a>\n <\/div>\n<\/div>\n<\/div>\n"}
