LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-17-2015, 03:43 AM   #1
Rownzy
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Rep: Reputation: Disabled
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
 
Old 06-17-2015, 04:02 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
1 members found this post helpful.
Old 06-17-2015, 04:21 AM   #3
Rownzy
LQ Newbie
 
Registered: Jun 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by zhjim View Post
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] log bash script output to file with timestamp daisychick Programming 11 05-08-2013 01:50 AM
[SOLVED] BASH: Use SYSLOG to write log to new log file worm5252 Programming 2 08-23-2012 11:17 AM
(Bash) Redirect all output from script to all.log and copy of errors to err.log hmsdefender Programming 5 03-05-2010 01:52 PM
Clean Up Log - Search for Pattern in Log file and Output result bridrod Linux - Newbie 10 01-05-2010 09:49 AM
time --output=log.txt --append sadarax Linux - General 1 05-22-2006 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:59 PM.

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