Linux batch modify server time

Preface

Time to modify the server time can have other effects,
such as simulation logs

Because the time value of the Java project log framework is based on the system time when the log is generated, we can modify the system time to simulate the generation of logs at different times.

Scripting

dt file:

#/bin/bash
#在 zjj101 zjj102上同步日期为指定的日期
if(($#==0))
then
	echo 请输入要修改的时间!
	exit;
fi

#修改系统时间
for i in zjj101 zjj102
do
	echo ------------同步$i时间--------------
	ssh $i "sudo date -s '$@'"
done

Test script

[root@zjj101 script]# sh dt 2020-02-13 11:11:11
------------同步zjj101时间--------------
2020年 02月 13日 星期四 11:11:11 CST
------------同步zjj102时间--------------
2020年 02月 13日 星期四 11:11:11 CST

You can view the current system time by using the date command in other Linux terminals.

Guess you like

Origin blog.csdn.net/qq_41489540/article/details/109103065