Re: [suse-axp] Eliminating the year2020 problem from the installation.

From: Alex Rhomberg (rhomberg@ife.ee.ethz.ch)
Date: Wed Jul 05 2000 - 03:01:20 PDT

  • Next message: Sven Denninghoff: "SuSE 6.4 on AS400"

    Message-ID: <39630770.4C70F25E@ife.ee.ethz.ch>
    Date: Wed, 05 Jul 2000 12:01:20 +0200
    From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
    Subject: Re: [suse-axp] Eliminating the year2020 problem from the installation.
    

    "G. Hugh Song" wrote:

    > I pleasantly found out that SuSE finally figured out how to get the
    > clock right at last with SuSE-6.4. Unfortunately, for some
    > historical reasons, I still have many files with time stamp 2020.
    >
    > Does anybody have a shell-script file that can change the year stamp
    > only?

    Here's a perl script I used. Given my perl today, I'd probably write the
    same now in 5 lines :-)
    You can't change the attributes of symlinks. If you want to change their
    data, you have to delete and link freshly.

    - Alex
    ===================================================================================

    #!/usr/bin/perl -w

    # chyear
    # changes access or modification year of a file
    # based on a program by Robert Harley
    # Author: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>

    #usage: first come the options (-a to modify access, -m to modify modify
    time)
    #then comes fromyear, then toyear, then the filenames
    #filenames can also be supplied through stdin

    #examples:
    #touch /tmp/now; find / -newer /tmp/now |chyear 2038 1998; rm /tmp/now
    #touch /tmp/now; chyear 2038 1998 `find / -newer /tmp/now`; rm /tmp/now

    my $usage =
      "Usage: $0 [-m] [-a] <fromyear> <toyear> [<file1> [<file2> [...]]]\n".
      "\t-m modifies modify time, -a the access time\n".
      "if no option is given, both times are modified\n".
      "if no filename is given, they are taken from stdin\n";

    use POSIX; # needed for mktime

    die $usage if $#ARGV < 1;

    my ($modacc, $modmod) = (0,0);

    while ($ARGV[0] =~ /^-(.*)$/) {
      shift;
      $modacc = 1 if $1 eq 'a';
      $modmod = 1 if $1 eq 'm';
      die $usage unless $1 =~ /^[am]$/;
    }

    $modacc = $modmod = 1 unless $modacc||$modmod;

    die $usage if $#ARGV < 1;

    my $fromyear = shift;
    my $toyear = shift;

    die "$0: years are strange\n" if (($fromyear < 1970) || ($fromyear >
    2037) ||
                                      ($toyear < 1970) || ($toyear >
    2037));

    if (@ARGV) {
      while(@ARGV) {
        $_ = shift;
        chyear($fromyear, $toyear, $_) unless -l $_;
      }
    } else {
      while (<>) {
        chomp;
        chyear($fromyear, $toyear, $_) unless -l $_;
      }
    }

    sub chyear {
      my $fy = shift() - 1900;
      my $ty = shift() - 1900;
      my $file = shift;

      my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
          $atime,$mtime,$ctime,$blksize,$blocks)
        = lstat($file);

      my @time = localtime ($atime);

      my $mod = 0;

      if($modacc) {
        if ($time[5] == $fy) {
          $time[5] = $ty;
          $atime = mktime(@time);
          $mod = 1;
        }
      }
      
      if ($mod) {
        print "changing $file\n";
        utime $atime, $mtime, $file if $mod;
      }
    }



    This archive was generated by hypermail 2.1.0 : Mon Jun 04 2001 - 04:18:24 PDT