Changing system time in HP-UX using perl


 
Thread Tools Search this Thread
Operating Systems HP-UX Changing system time in HP-UX using perl
# 1  
Old 01-27-2011
Changing system time in HP-UX using perl

Hi All,

I would like to change system time for my testing purposes. All I need is to change the system time forward/backward in seconds.

I am providing the perl code that I am using to change system time on all platforms.
---------
Code:
use strict;
use English;

my $sec;    my $mday;   my $wday;
my $min;    my $mon;    my $yday;
my $hour;   my $year;   my $isdst;

my $time=time();
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($time+$ARGV[0]);

$year += 1900;
$mon  += 1;

if (length($mon)  == 1) {$mon = "0$mon";}
if (length($mday) == 1) {$mday = "0$mday";}
if (length($hour) == 1) {$hour = "0$hour";}
if (length($min)  == 1) {$min = "0$min";}
if (length($sec)  == 1) {$sec = "0$sec";}

if ($OSNAME eq "MSWin32")
{
  open (BATFILE, ">chgtime.bat");
  print BATFILE "time $hour:$min:$sec\n";
  print BATFILE "date $mon/$mday/$year\n";
  close BATFILE;
  system("chgtime.bat");
}

elsif ($OSNAME eq "solaris")
{
  system("$run_as_root 'date $mon$mday$hour$min$year.$sec'");
}

elsif ($OSNAME eq "aix")
{
  $year = sprintf("%02d", $year % 100); # last two digits of the year
  system("$run_as_root 'date $mon$mday$hour$min.$sec$year'");
}
elsif ($OSNAME eq "hpux")
{
# There is no 'seconds' field in HP-UX.
# date [-u] [mmddhhmm[[cc]yy]]
# date [-a [-]sss[.fff]]
# Need to sleep 30sec for 1sec time change using 'date -a'  

  if($ARGV[0] >= -60 && $ARGV[0] <= +60) {
    # 'date -a' will not accept '+' sign, but accepts '-' sign
    # 'date -a +60' is not valid whereas 'date -a 60' and 'date -a -60'are valid
    $ARGV[0]=~tr/^+//d;     # removing '+' sign
    system("$run_as_root 'date -a $ARGV[0]'");
    $ARGV[0]=~tr/^-//d;     # removing '-' sign 
    sleep($ARGV[0]*30);
  }
  else {
    system("echo 'yes'|$run_as_root 'date $mon$mday$hour$min$year'");
  }
}

-----------------------------
Here for HP-UX there is no single command to change the time in seconds.
Suppose if i want to change the time by +5 seconds, I have to wait for 150 seconds using 'date -a' command. But I want to change the time without wait as in other platforms.

I would appreciate if you could provide me solution.

Thanks

Last edited by pludi; 01-27-2011 at 04:28 AM.. Reason: code tags, please...
# 2  
Old 01-27-2011
Interesting...
Since it seems you cannot achieve what you want easily, why dont you try to set up a NTP server where you would just have to modify at your will the time in seconds and let the poor "slaves" do the rest?
# 3  
Old 02-01-2011
Thanks for the reply. Could you please let me know how to setup the same?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

2. AIX

changing the time zone in aix

hi may aix version is 6100-06-03-1048 when i give date command it shows the time zone as root@cbspsgui01 #date Fri Sep 16 08:43:42 Africa/Johannesburg 2011 I want to change the time zone to GMT +02:00: After i change the time zone it should show something like the one below when i type... (2 Replies)
Discussion started by: newtoaixos
2 Replies

3. Shell Programming and Scripting

Why does the 'pid' keep changing every time?

HI I checked the pid of a process on my machine using this command. ps -ef | awk '/process_name/{ print $2 }' I get the result as 12245 I check it again after 2 mins, I get the result as 12264 I check it again after 2 mins, I get the result as 12289 It keeps on this. How does this pid... (4 Replies)
Discussion started by: ss3944
4 Replies

4. AIX

changing server time

Hi all, we have IBM- AIX 5.2 operating system on that we have our oracle production database and there is daily crontab script for backup. my boss told me to change the server time.if i change the server time by root user does it give problem to any application or script which are... (2 Replies)
Discussion started by: younusdba
2 Replies

5. Solaris

getting time independent of system time in solaries

i am using function gethrtime() in sun solaries to get the time independent of the system time.Problem with this function is if we restart the system time will change to '0'.is there any other way to resolve this problem. thanks & regards suresh (3 Replies)
Discussion started by: suresh_rtp
3 Replies

6. Shell Programming and Scripting

System time comparison to fixed defined time

I have a requirement of checking the current system time and performing certain actions in a shell script. example: if the current system time is greater than 1400 hrs, then perform step 1,2,3 if the current system time is greater than 1000 hrs, then perform step 1,2 if the current system time... (2 Replies)
Discussion started by: zainravi
2 Replies

7. Shell Programming and Scripting

Need help in changing Mod time of a file

I have a file called MasterRECEIVEFranScript. I need to change its modified time to Sep 20 09:34 2008 For this i have tried a command ,but no success touch -m -t 1222079885 MasterRECEIVEFranScript ------------------------------------------------------------- Plz help me in this ? ... (6 Replies)
Discussion started by: ali560045
6 Replies

8. Shell Programming and Scripting

changing modified time

How to change the modified time of a file to any specified time. ls -ltr drwxr-xr-x 2 pipe pipe 4096 Jun 10 10:33 coredump_06062008 ---------------------------------------------------------------------- here file coredump_06062008 last modified time is Jun 10 10:33 and i... (1 Reply)
Discussion started by: ali560045
1 Replies

9. Solaris

[help] changing time on solaris 8 sparc

hi expert, i have a problem to change time on my box V890 sparc, as below : % su % date 1200.00 the time is changed but after i logout and login again the date is come to existing. how to change the date/time permanently without restart ? thank you bucci (2 Replies)
Discussion started by: bucci
2 Replies

10. UNIX for Dummies Questions & Answers

How to MV without changing Time Stamp

Hi, I need to move the set of files, and it should be same time stamp as previous. How to do this? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question