func checkTimeSync(s ssh.Interface, ipList []string) error {标签:同步,return,err,主机,fmt,Errorf,ip,go,timeStamp From: https://www.cnblogs.com/cheyunhua/p/17426475.html
logger.Info("checker:timeSync %v", ipList)
for _, ip := range ipList {
timeStamp, err := s.CmdToString(ip, "date +%s", "")
if err != nil {
return fmt.Errorf("failed to get %s timestamp, %v", ip, err)
}
ts, err := strconv.Atoi(timeStamp)
if err != nil {
return fmt.Errorf("failed to reverse timestamp %s, %v", timeStamp, err)
}
timeDiff := time.Since(time.Unix(int64(ts), 0)).Minutes()
if timeDiff < -1 || timeDiff > 1 {
return fmt.Errorf("the time of %s node is not synchronized", ip)
}
}
return nil
}