AnswerBun.com

fping with timestamp logging to file named with date

Hello.
Using my server to log network DC’s that seem to occur sporadicly during the days.
Looked around and collected code and got this to work, wich i launch via cronjob to get one textfile a day.

The program:

#!/bin/bash

## Get current date ##
_now=$(date +"%d_%m_%Y")

## Appending a current date from a $_now to a filename stored in $_file ##
_file="/path/to/file/pinglogger_$_now.txt"

## fping 24h with timestamp to a file with todays date ##
fping -c 86000 -s google.com 192.168.250.1 | while read pong; do echo "$(date): $pong"; done > "$_file" 2>&1

The problem:
This works, but i do not get the last lines of ping statistics when the program ends. Problem started when i found and added | while read pong; do echo "$(date): $pong"; done to the program to add timestamp on the pings.

The soultion:
After tips and trix, final code is this and it writes stout and sterr to output file: pings local host and google for approx 1 day to a file with todays date.:

#!/bin/bash

## Get current date ##
_now=$(date +"%d_%m_%Y")

## Appending a current date from a $_now to a filename stored in $_file ##
_file="/path to file/pinglogger_$_now.txt"

## fping 24h with timestamp to a file with todays date ##
(fping -c 86000 -s google.com 192.168.250.1 | ts) &> "$_file"

Ask Ubuntu Asked by disco_rogge on December 30, 2020

1 Answers

One Answer

Using TS to short it down and putting code in () piping bot sterr and stout to file worked.

(fping -c 86000 -s google.com 192.168.250.1 | ts) &> "$_file"

Correct answer by disco_rogge on December 30, 2020

Add your own answers!

Related Questions

I cannot unzip.tgz file in my external hard drive

1  Asked on December 23, 2021 by ubuntu-beginner

     

Ubuntu 20.04 being hacked

2  Asked on December 23, 2021 by albert-g-lieu

   

Rekordbox alternative for ubuntu

2  Asked on December 21, 2021 by silb

     

How to configure a NFS mounting in fstab?

2  Asked on December 21, 2021 by nicholas-parmentier

     

GNOME- software not working

1  Asked on December 21, 2021

   

Reconnect Samba Share after router replacement

1  Asked on December 21, 2021 by adan-burlington

 

Can not login after Nvidia driver installation

2  Asked on December 20, 2021 by user224685

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.