Skip to content

Instantly share code, notes, and snippets.

@David-Lor
Created December 14, 2020 11:07
Show Gist options
  • Save David-Lor/3c546f5c546c88f4c76cde57d3b646e9 to your computer and use it in GitHub Desktop.
Save David-Lor/3c546f5c546c88f4c76cde57d3b646e9 to your computer and use it in GitHub Desktop.
Ping > CSV logger
#!/bin/bash
# Usage: ./ping2csv.sh enp2s0 8.8.8.8
# (will ping 8.8.8.8 using interface enp2s0)
#
# Will store ping results on a file named "ping-enp2s0-8.8.8.8.csv" with lines as:
# 2020-01-01 10:15:30,15.234
set -x
INTERFACE="$1"
IP="$2"
while true
do
result="""$(ping -qc1 -I $INTERFACE $IP 2>&1 | awk -F'/' 'END{ print (/^rtt/? ""$5"":"-1") }')"""
now="""$(date +"%Y-%m-%d %H:%M:%S")"""
echo "$now,$result" >> "ping-$INTERFACE-$IP.csv"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment