I've to run some reports on a particular host (HOST A). The commands being run on the this host (HOST A) can collect some information from remote servers, but not the 'current' server time of these remote hosts. Also, I don't have permission to connect to the hosts remotely or collect the time using ssh or rsh (rsh date) from HOST A.

So, I post two questions:-

  1. Is there a way to find the 'current' server time of the remote hosts by not using ssh/rsh.

  2. Can someone help me with a time calculation script based on GMT time settings. (I can do a date -u to collect the GMT time on HOST A and calculate the approx. time on remote host based on GMT time and remote host's Timezone. All hosts in the environment are updated using synced NTP servers)

I'm using BASH on Solaris 10 (preferred) / RHEL 6

Thanks in Advance!

有帮助吗?

解决方案

Do you want something like

getZoneOffset() {
  #assume ./zones.txt contains lines like
  #example.com 3600
  #i.e. host and time offset in seconds
  remote=$1
  set - $(grep "$1" ./zones.txt)
  echo $2
}

zoneOffsetSecs=$(getZoneOffset $remote)
now=$(date -u +%s)
there=$((now+zoneOffsetSecs))
date -d @$there

You may want to add error handling for cases where your remote host is not found in your zones.txt file.

其他提示

I've achieved the result using the below method, seems good till now, but suggestions are most welcome

bash-4.1$ nowgmt=`date -u|awk '{print $4}'|awk -F: '{print ($1 * 3600) + ($2 * 60) + 50400}'`
bash-4.1$ tzoffset="10:30"
bash-4.1$ offsettime=`echo $tzoffset | awk -F: '{print ($1 * 3600) + ($2 * 60)}'`
bash-4.1$ thertime=$((nowgmt + offsettime))
bash-4.1$ date -d @$thertime | awk '{print $4}'
08:46:00
bash-4.1$ date -d @$thertime | awk '{print $4}' | cut -d ":" -f1-2
08:46
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top