-1

Is it possible to run a specific script and receive a message (like msg command) when the pinged machine becomes available?

ping -n <Address> | find "TTL=" && (
msg * Online
)
Filburt
  • 17,626
  • 12
  • 64
  • 115
Alphabet
  • 3
  • 2
  • Why not use a simple batch file with a label looping mechanism! 1. ```:loop```, 2.```@ping.exe -n
    2>nul | find.exe "TTL=" 1>nul && (msg.exe * Online) || goto loop```. If you wanted to reduce the frequency of checks, to say every 3 seconds, change ```goto loop``` to ```timeout.exe /t 3 /nobreak 1>nul & goto loop```.
    – Compo Dec 07 '22 at 13:27

1 Answers1

0

Here is a PowerShell way:

ping -t <Address> | Select-String 'TTL=' | Select-Object -First 1
msg * Online
  • ping -t <Address> repeatedly pings the given host.
  • Select-String 'TTL=' searches each output line of ping for the given RegEx pattern. If found, it is piped to the next command.
  • Select-Object -First 1 ends the pipeline as soon as the first line has been found.
  • This outputs the line containing "TTL=" to the console. If you don't want this, append | Out-Null.
zett42
  • 25,437
  • 3
  • 35
  • 72