tags:

views:

120

answers:

4

Does anyone know how to write a bash script that will pull the time off of another server? I need a script that will poll the other server's time and start an event at a very specific period of time based on the time on the external server.

+3  A: 

Why not just sync the time using NTP then use Cron to fire off the script at the appropriate time?

Chris S
I do not have permissions to use NTP. I just need to run a few tests that fire off at a certain time on the external system.
Matt Pascoe
A: 

I second the use of NTP as it is the best way to get an accurate time synchronisation. You may need to install an NTP server on the external server if it doesn't already have one.

Cron will allow you to schedule a task down to the minute level. If you need it to be scheduled to a specific second or even more accurately, then you may need to write a program to poll the time and sleep as appropriate.

ar
A: 

Well this will help you if you don't have strong time constraint.

You could write a script that will execute a script containing your command "date" In other words...

first script: remote_ssh.sh

#!/bin/bash

#connect to $machine and execute the script script2execute.sh

ssh $machine bash script2execute.sh

second script:` script2execute.sh

#!/bin/bash

# store your time on a file( or even a variable as you wish)

date > TIME.txt

+2  A: 
ssh [email protected] "date +%Y%m%d%H%M%s"
ghostdog74
This will work, assuming you have ssh access to the remote machine. Of course, 'works' and 'good idea' are not always the same thing. For instance, if anyone changes the time forward on the remote machine, you're test will likely not fire off (assuming it should have run between the old time and the new time).
Chris S