#!/usr/bin/env bash #all hosts should to sync time, all hosts should no password login echo othersynchosts_array=('xufeng-1' 'xufeng-2') #currnt time in this hostcurrentDay=`date '+%Y-%m-%d'`currentTime=`date '+%H:%M:%S'`echo 'current day in this host is 'echo $currentDayecho 'current time in this host is 'echo $currentTime #loop host to set timefor hostname in ${synchosts_array[*]}do echo $hostname ssh -t $hostname bash -c ''date -s '$currentDay' &&hwclock --systohc'' ssh -t $hostname bash -c ''date -s '$currentTime' &&hwclock --systohc''done