#!/usr/bin/perl # copyright (c) 2004,2005 Scalable Informatics LLC # this is open source software licensed under the GPL v2.0 use constant Ndisks => 2; use constant Days_per_month => 31; use strict; use POSIX qw(strftime); use Getopt::Long; my ($date,$fraction,$index,$rc,$dir,$link,$to); $date = strftime "%d",localtime; $fraction = Days_per_month/Ndisks; $index = int(($date-1)/$fraction)+1; # make sure that the range of dates is from 0 .. Days_per_month-1 # to simplify extracting the integer portion. We want to make sure # that we have the index vary from 1 .. Ndisks and not 1 .. Ndisks+1 # so we shift the date down by one. First day is zero ... $dir = "/media/usbdisk"; $link = "/media/backup"; $rc = GetOptions ( "dir=s" => \$dir, "link=s"=> \$link ); $to = sprintf("%s%s",$dir,$index); printf "date = %s, index = %s, link to = %s\n",$date,$index, $to; $rc = `/bin/rm -f $link`; $rc = `/bin/ln -s $to $link`;