Tag Info

New answers tagged


The "Network is not reachable" message is printed to stderr, not stdout, so it isn't captured by your substitution ($(ping ...)). You need to redirect stderr to stdout when running ping, not when you log: print_and_log "$(ping -c10 "$i" 2>&1)"


Simply use below in command line. echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all


I try to avoid ping, as anything can intercept and respond to the echo — even if it isn't the intended target. Here's what I use — hope it helps: #===== FUNCTION ============================================================= # NAME: validateServerAvailability # DESCRIPTION: Validates that a given host exists in DNS and is alive # ...


If you are using bash, you can try this short script: #!/bin/bash while IFS= read -r host; do [[ $(ping -c4 "$host") ]] 2>/dev/null && echo "$host" >> /path/to/result.txt done < /path/to/domains.txt Here i have assumed that the hosts in domains.txt are newline separated. EDIT: Here is the modified script with ping being verbose ...


On another server I was getting awk: line 2: function strftime never defined and there is no easy way to install gawk so I figured out how to do it without awk just with date (as per @Hrvoje Špoljar's hint) ping -D localhost | while read row ; do if [[ $row == \[*\]* ]]; then echo -n \[$(date -d "@$(echo $row| sed 's/^\[//' | sed 's/\].*//')")\] ; fi ; ...


grep with extended regex: ping ... | grep --line-buffered -E 'time=([0-9]{4}|[5-9][0-9]{2})' | ... This will match any line with time= followed immediately by either: Any 4 digits (1000+ ms). One digit 5-9 followed by any 2 digits (500-999 ms). --line-buffered works around issues caused by grep's default output buffering when used in a pipe chain. Not ...


Perl solution: ping -i "$2" "$1" | while read pong; do echo $(date) "$pong" ; done \ | perl -ne 'print if (/time=([0-9.]+)/)[0] > .5' >> ~/Downloads/... Explanation: - ([0-9.]+) matches the decimal number after time= and remembers it - (...)[0] returns the first element of the given list (needed to switch from list to scalar)

Top 50 recent answers are included