From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Werner.Rost@zfboge.com Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: modify system time Date: Mon, 28 Jul 2003 16:24:58 +0200 Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <923B59E7C539B94FAD82D0D375B69CDACC20F1@BNNS00001> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: main.gmane.org 1059402322 31794 80.91.224.249 (28 Jul 2003 14:25:22 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 28 Jul 2003 14:25:22 +0000 (UTC) Original-X-From: tru64-unix-managers-owner-gotm-tru64-unix-managers=m.gmane.org@sws1.ctd.ornl.gov Mon Jul 28 16:25:21 2003 Return-path: Original-Received: from sws1.ornl.gov ([160.91.1.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 19h8vl-0008EN-00 for ; Mon, 28 Jul 2003 16:24:53 +0200 Original-Received: (qmail 6144 invoked by uid 5); 28 Jul 2003 14:24:50 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 6135 invoked by uid 49493); 28 Jul 2003 14:24:49 -0000 Original-Received: from Werner.Rost@zfboge.com by sws1 by uid 49491 with qmail-scanner-1.16 (clamscan: 20030605. spamassassin: 2.55. Clear:SA:0(0.8/5.0):. Processed in 0.451577 secs); 28 Jul 2003 14:24:49 -0000 Original-Received: from unknown (HELO emroute2.cind.ornl.gov) (160.91.86.17) by 0 with SMTP; 28 Jul 2003 14:24:49 -0000 Original-Received: from emroute2.cind.ornl.gov (LOCALHOST [127.0.0.1]) by emroute2.cind.ornl.gov (PMDF V6.2 #30669) with ESMTP id <0HIQ00A66O1CM6@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Mon, 28 Jul 2003 10:24:48 -0400 (EDT) Original-Received: from sunny.mannesmann.de (sunny.mannesmann.de [195.233.129.34]) by emroute2.cind.ornl.gov (PMDF V6.2 #30669) with ESMTPS id <0HIQ00A3LO0ZN1@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Mon, 28 Jul 2003 10:24:37 -0400 (EDT) Original-Received: from mailtest.vodafone.com (mailtest.vodafone.com [195.233.128.119]) by sunny.mannesmann.de (Switch-2.2.6/Switch-2.2.6) with ESMTP id h6SEOX305836 for ; Mon, 28 Jul 2003 16:24:33 +0200 (MEST) Original-Received: from bnns00001.zfbn.zf-group.de ([192.125.129.6]) by mailtest.vodafone.com (Switch-2.2.6/Switch-2.2.6) with ESMTP id h6SEOW214737 for ; Mon, 28 Jul 2003 16:24:32 +0200 (MEST) Original-Received: by BNNS00001 with Internet Mail Service (5.5.2653.19) id ; Mon, 28 Jul 2003 16:25:02 +0200 Content-return: allowed Original-To: tru64-unix-managers@ornl.gov X-Mailer: Internet Mail Service (5.5.2653.19) Xref: main.gmane.org gmane.os.tru64.managers:4952 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:4952 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.