LinuxQuestions.org
Visit Jeremy's Blog.
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 11-10-2007, 10:07 PM   #1
thefox
LQ Newbie
 
Registered: Nov 2007
Posts: 1

Rep: Reputation: 0
Adding timestamp to a BASH script


I am writing a bash script to ping a website at certain times of the day and I need to know how to either write the ping data to a text file to view later or to echo the time and date upon completion of the ping. I will be running the script constantly and won't be there to start and stop it so I need to automate the process as much as possible. I am running Fedora Core 7. Also what is the command to delay the script. For example to pause it until 1 (one) hour later and then restart the ping writing each ping data to a new text file.
 
Old 11-10-2007, 10:29 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Hi,

And welcome to LQ!


You're best option for that task would be to use cron

As for the content (plus time-stamp of the ping into a file with the
timestamp as the file-name) ...

ping host > `date "+%Y%m%d-%H:%M` 2>&1

If you put that inside a script, make it executable [chmod +x script]
and invoke that from cron (assuming that your distro doesn't replace
the default editor (vi) with something more 'user-friendly') here's
what to do (verbatim) to set it up to run every hour:
Code:
crontab -e
i
0 * * * * * /path/to/script
ESC
:wq




Cheers,
Tink
 
  


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
Adding script file on Bash greatmenon Linux - Software 1 01-21-2006 08:14 AM
adding a rotating - to my bash script Cinematography Programming 3 08-31-2005 02:05 PM
bash script for adding multiple users pilipk01 Linux - Newbie 4 01-12-2004 11:05 PM
adding timestamp to name niehls Linux - General 2 12-05-2003 11:40 AM
Need help adding an IF / ELSE statement to my Bash Script Relix Linux - General 1 08-01-2002 03:03 PM

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

All times are GMT -5. The time now is 05:32 AM.

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