LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-26-2022, 01:31 AM   #1
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Rep: Reputation: 1
5 seconds ping to TSVs


I recently had connection issues and used
Code:
date +"%Y-%m-%d"; while true ; do ping -n 1 google.ca | head -n 3; date +"%T" ; sleep 5 ; done
in a console for my short-term documentation. I'd like to do something similar for longer-term, so I'd like it to be output to a file. I'd like for the output to be in "pinger-5secs-YYMMDD.tsv" and for the TSV to contain the columns "Time" & "Reply ms".

I'm thinking for reply ms the above (
Code:
ping -n 1 google.ca | head -n 3
) can be taken and run through a regex for the # right after "ms=", and if there's none insert something to show that, ie the character ' ⃠ '. I foresee the time remaining the same (
Code:
date +"%T"
). Of course since it's a TSV, a tab between the 2.

Thank you kindly for your help

Last edited by DynV; 11-26-2022 at 01:33 AM.
 
Old 11-26-2022, 08:03 AM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
Example:
Code:
echo $(date +"%Y-%m-%d") >> pinger-5secs-YYMMDD.tsv

while :; do 
    echo -e "\n$(date +"%T")" >> pinger-5secs-YYMMDD.tsv
    echo $(ping -c1 127.0.0.1) >> pinger-5secs-YYMMDD.tsv
    sleep 5
done
 
Old 11-26-2022, 08:15 AM   #3
DynV
Member
 
Registered: Feb 2020
Location: Montreal, Canada
Distribution: Ubuntu 22.04.2
Posts: 51

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by teckk View Post
Example:
Code:
echo $(date +"%Y-%m-%d") >> pinger-5secs-YYMMDD.tsv

while :; do 
    echo -e "\n$(date +"%T")" >> pinger-5secs-YYMMDD.tsv
    echo $(ping -c1 127.0.0.1) >> pinger-5secs-YYMMDD.tsv
    sleep 5
done
YYMMDD is to be replaced by the date of the same format. Only the # in "ms=#" is to be kept from the ping. I don't see a tab being used to separate the data in 2 columns.
 
Old 11-26-2022, 09:15 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
Write it the way that you wish. Show the script that you have written, and where it is having problems. The idea is for you to do it yourself. Not someone write it for you.

Quote:
YYMMDD is to be replaced by the date of the same format.
Code:
a="pinger-5secs-"
b=$(date +"%Y-%m-%d")

echo ""$a""$b".tsv"
pinger-5secs-2022-11-26.tsv
Quote:
I don't see a tab being used to separate the data in 2 columns.
Then make it they way you want it to be.
Code:
a="one"
b="Two"

echo -e ""$a"\t"$b""
one     Two
See:
man echo
 
Old 11-26-2022, 09:52 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,981

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
Oh, no Useless use of echo
Code:
a="pinger-5secs-"
b=$(date +"%Y-%m-%d")
filename="$a$b.tsv"
while ;: do
    ping -c1 127.0.0.1
    date +"%T"
done > "$filename"
(intentionally non-working example)
 
Old 11-26-2022, 10:22 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,710

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by DynV View Post
I recently had connection issues and used
Code:
date +"%Y-%m-%d"; while true ; do ping -n 1 google.ca | head -n 3; date +"%T" ; sleep 5 ; done
in a console for my short-term documentation. I'd like to do something similar for longer-term, so I'd like it to be output to a file. I'd like for the output to be in "pinger-5secs-YYMMDD.tsv" and for the TSV to contain the columns "Time" & "Reply ms".

I'm thinking for reply ms the above (
Code:
ping -n 1 google.ca | head -n 3
) can be taken and run through a regex for the # right after "ms=", and if there's none insert something to show that, ie the character ' ⃠ '. I foresee the time remaining the same (
Code:
date +"%T"
). Of course since it's a TSV, a tab between the 2.

Thank you kindly for your help
You can use an already-existing tool for such things, unless you very specifically NEED a TSV file
https://oss.oetiker.ch/smokeping/
 
Old 11-26-2022, 12:28 PM   #7
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,246

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Trying pinging by IP as well as by domain name (to see if the problem is DNS), also do a traceroute (to see where the delay actually is).
 
Old 12-03-2022, 08:59 AM   #8
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,008

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
Some or many routers along the path might have been set to delay or deny ping on load. Ping isn't a great tool anymore. Use other tools for displaying the full path and in the IP version you want or need.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I cannot ping with command 'ping IP' address but can ping with 'ping IP -I eth0' sanketmlad Linux - Networking 2 07-15-2011 05:32 AM
convert total no of seconds in the format hour minutes and seconds suchi_s Programming 15 03-15-2011 11:34 AM
[SOLVED] Experiencing freezing up to 5 seconds every 10 seconds, could these be the problem? Switch7 Slackware 10 11-16-2009 04:36 PM
hdparm power save, 15 seconds of spin, 5 seconds of rest... Romanus81 Linux - Laptop and Netbook 1 01-01-2009 05:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration