From: Werner.Rost@zfboge.com
Subject: SUMMARY: modify system time
Date: Mon, 28 Jul 2003 16:24:58 +0200 [thread overview]
Message-ID: <923B59E7C539B94FAD82D0D375B69CDACC20F1@BNNS00001> (raw)
Thanks a lot to
Jim Fitzmaurice [jpfitz@fnal.gov]
Jay Leafey [jleafey@utmem.edu]
Mark Scarborough [mscar-osf@cactus.org]
for their hints. This list is very helpful.
I realized Jays solution using a perl script:
#!/usr/bin/perl -w
($mon,$day,$year,$hour,$min) = (localtime(time()+(60*60*2)))[4,3,5,2,1];
$newdate = sprintf "%02u%02u%02u%02u%04u",
$mon+1, $day, $hour, $min, $year+1900;
print "date $newdate\n";
exec "date $newdate";
Jims solution:
#!/bin/ksh
DAY=`date +"%d"`
MON=`date +"%m"`
MIN=`date +"%M"`
YEA=`date +"%Y"`
HOR=`date +"%H"`
HOU=`expr $HOR + 2`
#
# Make sure hour doesn't exceed 24.
#
if [ $HOU -ge 24 ]
then
HOU=`expr $HOU - 24`
DAY=`expr $DAY + 1`
fi
#
# Ensue HOU and DAY are two digit numbers.
#
case $HOU in
?) HOU=`echo 0$HOU` ;;
esac
#
case $DAY in
?) DAY=`echo 0$DAY` ;;
esac
#
SEC=`date +"%S"`
#
# Set date
#
/bin/date $MON$DAY$HOU$MIN$YEA.$SEC
#
exit
#
Marks two solutions:
1) get 'gnudate' and use:
$ gnudate --date="+2 hours"
2) do the "timezone trick":
(for me, in CST6CDT)
$ date
Fri Jul 25 10:10:09 CDT 2003
$ TZ=CST4CDT date
Fri Jul 25 12:10:24 CDT 2003
It looks to me like you are probably in GMT-2 timezone. If so, you could
do this:
$ TZ=GMT-2 date
Fri Jul 25 17:11:42 GMT 2003
$ TZ=GMT-4 date
Fri Jul 25 19:11:46 GMT 2003
This trick very much depends on what timezone your system is set for so it
is not exactly the best, most portable solution, but it does work if you
are careful.
----------------------------------------------
Original problem:
I need a script which add 2 hours to the actual system time and then
"correct" the system time:
1. t = date (actual system time say 9:13h)
2. t := t + 2 hours 9:13h --> 11:13h
3. date = t (set system time to 11:13h)
Maybe somebody has done this and can tell me how to do.
reply other threads:[~2003-07-28 14:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox