LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   BASH - Log specific output to a log.txt file (https://www.linuxquestions.org/questions/linux-software-2/bash-log-specific-output-to-a-log-txt-file-4175545595/)

Rownzy 06-17-2015 03:43 AM

BASH - Log specific output to a log.txt file
 
Hi,
I was wondering if it is possible to write a script that will ping a specific target and if there will be no response (Timeout) it will log the timeout to a text file with a time stamp.

Your help is much appreciated :)

zhjim 06-17-2015 04:02 AM

Possible sure. Also depends on your skill. And as well a choice of scripting language to use.

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ should get you started if you want to use BASH.
You could also use perl as its installed on most linux distributions per default.

As soon as you have your script maybe use cron to have it run on a schedule. If you are stuck with any of this try man cron or man crontrab on a command line.

Example bash script
Quote:

ping $TARGET
if [ $? -ne 0 ]; then
date > /tmp/logfile
fi

Rownzy 06-17-2015 04:21 AM

Quote:

Originally Posted by zhjim (Post 5378499)
Possible sure. Also depends on your skill. And as well a choice of scripting language to use.

http://www.tldp.org/LDP/Bash-Beginners-Guide/html/ should get you started if you want to use BASH.
You could also use perl as its installed on most linux distributions per default.

As soon as you have your script maybe use cron to have it run on a schedule. If you are stuck with any of this try man cron or man crontrab on a command line.

Example bash script

Thanks a lot for your help Sir!


All times are GMT -5. The time now is 10:55 PM.