I have a ping file like this
PING 172.17.9.1 (172.17.9.1) 1000(1028) bytes of data.
1008 bytes from 172.17.9.1: icmp_seq=1 ttl=64 time=0.943 ms
1008 bytes from 172.17.9.1: icmp_seq=2 ttl=64 time=0.855 ms
1008 bytes from 172.17.9.1: icmp_seq=3 ttl=64 time=0.860 ms
.
.
--- 172.17.9.1 ping statistics ---
100 packets transmitted, 100 received, 0% packet loss, time 9958ms
rtt min/avg/max/mdev = 0.836/1.710/37.591/4.498 ms
I want to extract the packet loss, time, average rtt with bash scripting. what should I do?!
Thanks
You can awk as
$ awk -F"[,/]" '/packet loss/{print $3} /rtt/{print " rtt",$2,$5}' input
0% packet loss
rtt avg 1.710
Try something like:
awk -F',|/' '/time/{x=$3$4}/rtt/{print x " " $5}' ping.txt | sed 's/[^0-9 .]*//g'
Output:
0 958 1.710
Related
I expect to see 1MiB in the wc's character count (which works at the bottom when 'tee' is writing to a file rather than a process substitution).
Is there something I'm missing about using process substitution with tee?
[192.168.20.40 (02b4b472) ~ 18:52:39]# dd if=/dev/zero bs=1M count=1 | tee >(dd bs=1M count=1 | wc | sed 's/^/ /' > /dev/stderr) | wc
0+1 records in
0+1 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.00022373 s, 36.6 MB/s
0 0 8192
0 0 81920
[192.168.20.40 (02b4b472) ~ 18:52:56]# dd if=/dev/zero bs=1M count=1 | tee /tmp/foo | wc
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0416881 s, 25.2 MB/s
0 0 1048576
[192.168.20.40 (02b4b472) ~ 18:53:41]#
Using tee -p handles the stdout, but not the process substitution... which still comes up short.
[192.168.20.40 (02b4b472) ~ 19:17:05]# dd if=/dev/zero bs=1M count=1 | tee -p warn >(dd bs=1M count=1 | wc | sed 's/^/ /' > /dev/stderr) | wc
0+1 records in
0+1 records out
8192 bytes (8.2 kB, 8.0 KiB) copied, 0.00084348 s, 9.7 MB/s
0 0 8192
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0417175 s, 25.1 MB/s
0 0 1048576
[192.168.20.40 (02b4b472) ~ 19:18:25]#
It happens on my macbook(OSX 10.15.4).
I'm not fully understanding this problem, and it doesn't happen in other PC(OSX 10.15.4), iTerm.
Both were done with full disk access on terminal, and same network.
ping / dig works
curl doesn't works(-4 -6 both not work)
browser works normally.
flushed dns and wifi, but not fixed.
Response:
$ curl -v google.com
* Trying 172.217.14.206...
* TCP_NODELAY set
* Immediate connect fail for 172.217.14.206: Operation not permitted
* Closing connection 0
curl: (7) Couldn't connect to server
$ dig google.com
; <<>> DiG 9.10.6 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59652
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 121 IN A 172.217.14.206
;; Query time: 244 msec
;; SERVER: 64.59.144.92#53(64.59.144.92)
;; WHEN: Tue May 19 14:36:01 PDT 2020
;; MSG SIZE rcvd: 55
$ ping 172.217.14.206
PING 172.217.14.206 (172.217.14.206): 56 data bytes
64 bytes from 172.217.14.206: icmp_seq=0 ttl=56 time=18.432 ms
64 bytes from 172.217.14.206: icmp_seq=1 ttl=56 time=169.908 ms
64 bytes from 172.217.14.206: icmp_seq=2 ttl=56 time=19.552 ms
64 bytes from 172.217.14.206: icmp_seq=3 ttl=56 time=156.050 ms
64 bytes from 172.217.14.206: icmp_seq=4 ttl=56 time=19.996 ms
64 bytes from 172.217.14.206: icmp_seq=5 ttl=56 time=291.853 ms
64 bytes from 172.217.14.206: icmp_seq=6 ttl=56 time=25.486 ms
64 bytes from 172.217.14.206: icmp_seq=7 ttl=56 time=20.511 ms
64 bytes from 172.217.14.206: icmp_seq=8 ttl=56 time=21.455 ms
64 bytes from 172.217.14.206: icmp_seq=9 ttl=56 time=20.323 ms
64 bytes from 172.217.14.206: icmp_seq=10 ttl=56 time=20.087 ms
64 bytes from 172.217.14.206: icmp_seq=11 ttl=56 time=18.373 ms
64 bytes from 172.217.14.206: icmp_seq=12 ttl=56 time=15.993 ms
64 bytes from 172.217.14.206: icmp_seq=13 ttl=56 time=17.147 ms
64 bytes from 172.217.14.206: icmp_seq=14 ttl=56 time=19.605 ms
64 bytes from 172.217.14.206: icmp_seq=15 ttl=56 time=19.699 ms
64 bytes from 172.217.14.206: icmp_seq=16 ttl=56 time=35.372 ms
64 bytes from 172.217.14.206: icmp_seq=17 ttl=56 time=30.903 ms
64 bytes from 172.217.14.206: icmp_seq=18 ttl=56 time=23.162 ms
64 bytes from 172.217.14.206: icmp_seq=19 ttl=56 time=19.313 ms
64 bytes from 172.217.14.206: icmp_seq=20 ttl=56 time=17.620 ms
64 bytes from 172.217.14.206: icmp_seq=21 ttl=56 time=20.619 ms
64 bytes from 172.217.14.206: icmp_seq=22 ttl=56 time=23.571 ms
64 bytes from 172.217.14.206: icmp_seq=23 ttl=56 time=15.806 ms
nc commands output
$ dig www.google.com
; <<>> DiG 9.10.6 <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5970
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 85 IN A 172.217.14.228
;; Query time: 31 msec
;; SERVER: 64.59.144.92#53(64.59.144.92)
;; WHEN: Thu May 21 14:59:11 PDT 2020
;; MSG SIZE rcvd: 59
$ nc -z -v 172.217.14.228 80
Connection to 172.217.14.228 port 80 [tcp/http] succeeded!
$ nc -z -v 172.217.14.228 443
Connection to 172.217.14.228 port 443 [tcp/https] succeeded!
telnet
$ telnet 172.217.14.228
Trying 172.217.14.228...
telnet: Unable to connect to remote host: Operation timed out
ssh
$ ssh git#github.com
PTY allocation request failed on channel 0
Hi XXXXX! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
It's happened because AV software blocked the curl. Thank you all.
I have a shellscript which pings a domain and echoes out failed or ok
the problem is that debian somehow caches the ping request and always ping the same domain even if i change it in the shellscript.
#!/bin/sh
# -q quiet
# -c nb of pings to perform
ping -c5 google.com
if [ $? -eq 0 ]
then
echo "ok"
else
echo "failed"
fi
Edit:
Current Output:
PING germandeathsystem.de (193.25.100.197) 56(84) bytes of data.
64 bytes from germandeathsystem.de (193.25.100.197): icmp_seq=1 ttl=64 time=0.100 ms
64 bytes from germandeathsystem.de (193.25.100.197): icmp_seq=2 ttl=64 time=0.063 ms
64 bytes from germandeathsystem.de (193.25.100.197): icmp_seq=3 ttl=64 time=0.052 ms
64 bytes from germandeathsystem.de (193.25.100.197): icmp_seq=4 ttl=64 time=0.101 ms
64 bytes from germandeathsystem.de (193.25.100.197): icmp_seq=5 ttl=64 time=0.060 ms
Expected Output:
PING google.com (172.217.16.78) 56(84) bytes of data.
64 bytes from ham11s01-in-f14.1e100.net (172.217.16.78): icmp_seq=1 ttl=55 time=5.45 ms
64 bytes from ham11s01-in-f14.1e100.net (172.217.16.78): icmp_seq=2 ttl=55 time=5.59 ms
64 bytes from ham11s01-in-f14.1e100.net (172.217.16.78): icmp_seq=3 ttl=55 time=5.49 ms
64 bytes from ham11s01-in-f14.1e100.net (172.217.16.78): icmp_seq=4 ttl=55 time=5.50 ms
64 bytes from ham11s01-in-f14.1e100.net (172.217.16.78): icmp_seq=5 ttl=55 time=5.46 ms
Why does it still ping germandeathsystem.de and not google.com?
I don't understand why the very first item returned by tracert is not the default gateway.
This is the output of Get-NetIPConfiguration
InterfaceAlias : Ethernet
InterfaceIndex : 4
InterfaceDescription : Intel(R) I210 Gigabit Network Connection
NetProfile.Name : Network
IPv6Address :
IPv4Address : 155.240.5.217
IPv6DefaultGateway :
IPv4DefaultGateway : 155.240.5.254
DNSServer : 1.1.1.1
1.0.0.1
When i do tracert:
tracert 1.1.1.1
Tracing route to 1dot1dot1dot1.cloudflare-dns.com [1.1.1.1]
over a maximum of 30 hops:
1 1 ms <1 ms <1 ms 155.240.5.252
2 <1 ms <1 ms <1 ms 11.20.112.125
3 <1 ms <1 ms <1 ms 11.82.1.12
4 <1 ms <1 ms <1 ms 11.74.32.10
5 <1 ms <1 ms <1 ms 10.76.249.4
6 1 ms 1 ms 1 ms 92.111.215.118
7 1 ms <1 ms <1 ms linx-lon1.as13335.net [195.66.225.179]
8 <1 ms <1 ms <1 ms 1dot1dot1dot1.cloudflare-dns.com [1.1.1.1]
Why is the very first item of tracert 155.240.5.252 instead of the ip of the default gateway 155.240.5.254?
Since default gateway is just a route entry which apply to every destinations but only has lowest priority, so most possible cause is that there is another route entry to 1.1.1.1 exist on the route table. You can simply use route print -4 to confrim it.
I am writing data in a text file as below by running a script. This data is updated every second.
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 2 Kb/s | Sent Packets: 18 Pkts/s | Received Packets: 12 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 20 Pkts/s | Received Packets: 13 Pkts/s
eth0: Sent Bytes: 15 Kb/s | Received Bytes: 4 Kb/s | Sent Packets: 33 Pkts/s | Received Packets: 25 Pkts/s
eth0: Sent Bytes: 1 Kb/s | Received Bytes: 3 Kb/s | Sent Packets: 19 Pkts/s | Received Packets: 12 Pkts/s
I want to make a graph of the # of bytes sent and the # of bytes received. Same for packets.
You can use https://github.com/holman/spark to create a graph with just shell script (although it only works with bash and not POSIX sh). You can watch it update in real time with watch.
graph.sh
!/bin/sh
field=1
tail "$1" | cut -d '|' -f $field | sed -e 's!.*: \([0-9]\+\) .*!\1!' | ./spark/spark
Interactive console
git clone https://github.com/holman/spark
your-process > logfile &
watch sh graph.sh logfile
Output
Every 2.0s: sh graph.sh logfile Fri Dec 19 22:22:04 2014
▁▁▁█▁