LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   send system time to a file (https://www.linuxquestions.org/questions/linux-newbie-8/send-system-time-to-a-file-662902/)

ust 08-14-2008 10:54 PM

send system time to a file
 
I would like to send the system tme to a log ( /tmp/log ) in every 5 seconds , now I manually run "date >> /tmp/log" in every 5 seconds , it is OK , but how can I let it automatically do it ? thx


What I would like the log is
===================
#vi /tmp/log
Fri Aug 15 11:50:15 GMT 2008
Fri Aug 15 11:50:20 GMT 2008
Fri Aug 15 11:50:25 GMT 2008
Fri Aug 15 11:50:30 GMT 2008
Fri Aug 15 11:50:35 GMT 2008
Fri Aug 15 11:50:40 GMT 2008

Mr. C. 08-14-2008 11:25 PM

Code:

while : ;  do
  date >> /tmp/log
  sleep 5
done


kwesadilo 08-14-2008 11:44 PM

You could make a shell script (which I will call sendtime) like this:
Code:

#!/bin/bash

while true
do
    date >> /tmp/log
    sleep 5
done

Make it executable with chmod u+x sendtime. Then you start it in the background with ./sendtime &.

There are ways to make it automatically start up when you start the computer or when you log in. If that was what you wanted, you'll have to wait for somebody more knowledgeable.

estabroo 08-15-2008 09:10 AM

If you are trying to debug clock problems on that box you'll need to have another machine do it. Essentially 2 scripts one on the other machine and one on the machine your doing the clock check on. Setup a ssh key so you can do passwordless connects, then run a script like those above except instead of the date command it does an ssh command that runs a script that does the date >> /tmp/log on the machine your doing the clock check on.


All times are GMT -5. The time now is 10:37 AM.