LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Adding timestamp to a BASH script (https://www.linuxquestions.org/questions/linux-software-2/adding-timestamp-to-a-bash-script-598699/)

thefox 11-10-2007 10:07 PM

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.

Tinkster 11-10-2007 10:29 PM

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


All times are GMT -5. The time now is 09:58 AM.