Okay, slightly strange/specific question, but I have a command on linux to ping a server 3 times, and return the number of successful replies
ping -c 3 google.com | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }'
I want to extend this so it creates a file on the server named “server_is_up.txt (if the server is up (ie – the number is 3), or writes a file “server_is_down.txt” (if the server is down, obviously).
Tried this but it didn’t work:
ping -c 3 google.com | grep 'received' | awk -F',' '{ print $2 }' | awk '{ if ($1 == 0) { > host_is_down.txt } else { > host_is_up.txt } }'
I’m sure it’s obvious, but can’t think where to put the “> host_is_down.txt” part.
Thanks
Try this: