Is there any possibility to start and log continuous ping command from the router without having an active ssh session from the PC while pinging? I'd like it to be running automatically without having the computer switched on meanwhile. I already have collectd-mod-ping, but this time I'd like to see the raw result of a long term continuous ping command in a log file.
# Add to startup sed -i -e "\$i (ping example.org &> /tmp/ping.log) &" /etc/rc.local # Start /etc/init.d/done boot # Stop killall -SIGINT ping # Log tail -f /tmp/ping.log # Edit startup vi /etc/rc.local
Sorry, but I'm not a programmer guy and no idea how to implement or run this script. Nor aware of mtr or Zabbix. Can you please help me with more details?
OK, thanks, I got it. But how can I make it continuous? It stops after 3 packets:
root@OpenWrt:~# sed -i -e "\$i (ping -D -i 5 220.127.116.11 &> /mnt/sda1/pinglog/ping.log) &" /etc/rc.local root@OpenWrt:~# /etc/init.d/done boot root@OpenWrt:~# killall -SIGINT ping root@OpenWrt:~# tail -f /mnt/sda1/pinglog/ping.log PING 18.104.22.168 (22.214.171.124) 56(84) bytes of data. [1606533664.365100] 64 bytes from 126.96.36.199: icmp_req=1 ttl=117 time=5.94 ms [1606533669.370755] 64 bytes from 188.8.131.52: icmp_req=2 ttl=117 time=6.74 ms [1606533674.375041] 64 bytes from 184.108.40.206: icmp_req=3 ttl=117 time=6.42 ms --- 220.127.116.11 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 10009ms rtt min/avg/max/mdev = 5.941/6.370/6.743/0.336 ms ^C root@OpenWrt:~#
I've updated the post above.
Perfect, many thanks! BTW I'm planning to let it run for one or month or more. Is there any way to modify the commands to log the result automatically in separate logs for each day instead of letting one log growing huge?
Rename the file and restart the service on schedule.
Log rotation example:
mv /tmp/ping.log /tmp/ping.log.$(date +%Y%m%d)
Ok, thanks! Seems I need to do that also because the entire log currently gets lost or overwritten once the router would be power reset for any unexpected reason. I guess I could find a detailed tutorial for scheduling cronjobs, but can you please help me with the commands I'll need to insert into the crontab for my specific case?
Especially how an updated new filename could be given automatically each day. With an increasing number in the filename for example.
You probably want to move the file with a cronjob at midnight, not at boot.
And first you'll need to stop the ping before the file is renamed.
Thanks a lot for the great support! All my issues are sorted by putting this into rc.local:
mv /mnt/sda1/pinglog/ping.log /mnt/sda1/pinglog/ping.log.$(date +%Y%m%d%H%M) (ping -D -i 5 18.104.22.168 &> /mnt/sda1/pinglog/ping.log) &
and these lines into crontab:
0 0 * * * killall -SIGINT ping 0 0 * * * /etc/init.d/done boot
If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.
Unfortunately the current ping command skips the messages which are telling the host is unreachable. I can notice connection problems and their lenght only by chasing for gaps in the log between the timestamps of each lines:
[1606846223.811520] 64 bytes from 22.214.171.124: icmp_req=13073 ttl=117 time=6.23 ms [1606846228.815676] 64 bytes from 126.96.36.199: icmp_req=13074 ttl=117 time=5.94 ms [1606847141.271821] 64 bytes from 188.8.131.52: icmp_req=13255 ttl=117 time=242 ms [1606847146.041619] 64 bytes from 184.108.40.206: icmp_req=13256 ttl=117 time=6.70 ms
Do you have any idea how to include also the "host is unreachable" ping messages in the log?
Ok, and do you have any idea how to include any more visible messages in the log indicating the destination address is down? It is very hard now to find that unless I already know it by experiencing the other effects of the comnnection problems.
BusyBox ping is stripped off so you can try to install this package:
But is is not a complete solution:
This means you cannot see the message when the host is down for a short time or drops pings intentionally.
That's why you can try other packages:
How can I find and download them?
root@OpenWrt:~# opkg list | grep -i MTR root@OpenWrt:~# opkg list | grep -i nping root@OpenWrt:~#
opkg update && opkg find mtr* && opkg find nping*
And how to install them?
root@OpenWrt:~# opgk install mtr -ash: opgk: not found root@OpenWrt:~# opgk install nping -ash: opgk: not found root@OpenWrt:~#
opkg install mtr nping
Ok, thanks. I did not find any options for nping command to display timestamp. Do you have any hint? Ping command display is by default.
opkg update ; opkg install screen and the log into the router, start a new screen session with
screen -RR, start your ping command
ping -c 3600 220.127.116.11, use Ctrl+a to disconnect from the running screen session, and
sreen -RR to reconnect to the most recent screen session. For a one-shot measurement that is nicer than going via rc.local..., for repeated measurements however screen is not a good solution.