However, in its default mode the standard Unix ping command will run continuously. Note the "echo -e \\a" syntax for emitting an "alert" (^G or BEL). $ while : do ping -c 1 -w 1 HostIPaddr >/dev/null || echo -e \\a sleep 2 done We can easily do the Unix equivalent of what Ed's doing in the Windows command shell: So, there you have it.īTW, if you want prettier output from this, you can dump various Standard Output to nul as follows:Ĭ:\> for /L %i in (1,0,2) do -n 1 HostIPaddr > nul || echo ^G) After this, I simply introduce a 1-second delay by pinging localhost twice (first ping instantly, second ping one second later). It's how we can make the echo command ring the system beep. That little ^G is created by holding down the CTRL key and hitting G. Note that it looks like I typed Shift-6 G, but I didn't. Of course, as always cmd1 & cmd2 means run cmd2 regardless of the success or failure of cmd1. This is more efficient than checking the %errorlevel% environment variable with an IF statement, but I digress. Likewise, we can use cmd1 || cmd2 to make the system run cmd2 only if cmd1 fails. As we've seen in earlier episodes, we can use cmd1 & cmd2 to make the shell run cmd2 only if cmd1 succeeded. If the ping command fails to get a response, I'll have it run the echo command to make a beep. At each iteration through the loop, I turn off command echo and ping the target host one time (ping -n 1). In other words, it'll run forever, or until someone kills it. This command starts out with a FOR /L loop, set with an iterator variable of %i that I won't use, counting from 1 to 2 in steps of 0. The solution to this one in Windows includes some useful constructs, so let's have at it with this fu:Ĭ:\> for /L %i in (1,0,2) do -n 1 HostIPaddr || echo ^G) "I want a string of commands that will ping a host and for each time a packet is missing (i.e. Paul threw down a challenge to Hal and me in e-mail just a few minutes ago:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |