[31592] in Perl-Users-Digest
Perl-Users Digest, Issue: 2851 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 4 14:19:40 2010
Date: Thu, 4 Mar 2010 11:19:28 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 4 Mar 2010 Volume: 11 Number: 2851
Today's topics:
Re: Return text left of first tab <dpich@polartel.com>
Re: Return text left of first tab <dpich@polartel.com>
Re: Return text left of first tab <jurgenex@hotmail.com>
Re: Return text left of first tab <cartercc@gmail.com>
Re: Return text left of first tab <tadmc@seesig.invalid>
Re: Return text left of first tab sln@netherlands.com
Re: Return text left of first tab <glennj@ncf.ca>
Re: Return text left of first tab <dpich@polartel.com>
tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
Re: tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
Re: tape rotations and tape autoloaders <tzz@lifelogs.com>
Re: tape rotations and tape autoloaders <spamtrap@piven.net>
Re: tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
Re: tape rotations and tape autoloaders <rocky.allen.ats@gmail.com>
Re: tape rotations and tape autoloaders <hjp-usenet2@hjp.at>
Re: tape rotations and tape autoloaders <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 04 Mar 2010 08:15:12 -0600
From: Don Pich <dpich@polartel.com>
Subject: Re: Return text left of first tab
Message-Id: <So2dnSZLTeDtXRLWnZ2dnUVZ_hadnZ2d@polarcomm.com>
> What have you tried to so far? Where are you stuck? Which part of your
> program doesn't produce the result you want? What behaviour are you
> observing compared to what behaviour are you expecting?
Here is my script as it stands right now:
#!/usr/bin/perl
use strict;
use warnings;
my $infile = 'Pannaway.txt';
my $outfile = 'BASIP.list';
open( INFILE, "< $infile" ) or die "Can't open $infile : $!";
open( OUTFILE, "> $outfile" ) or die "Can't open $outfile : $!";
while (<INFILE>){
if (/BAS-ADSL/)
{
my ($line) = $_;
my @values = split('\.', $data);
foreach my $val (@values) {
$val = sprintf("%02x", $val);
printf OUTFILE $val;
}
print OUTFILE "\n";
} else {
}
}
close (INFILE);
close (OUTFILE);
After the 'my ($line) = $_;' line, I need to eliminate everything after
and including the first tab of a line in Pannaway.txt. Then send what is
left (IP Address column only) into the my@values to convert the dotted
quad ip address into a hex representation of the ip.
snippet of 'Pannaway.txt':
IP Address Name Type MAC Address
Firmware
10.21.65.252 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
3.2.1.28
10.21.66.252 ADMS.02.01 BAS-ADSL24R 00:0A:9F:00:D4:A5
3.2.1.28
10.21.66.250 ADMS.03.01 BAS-ADSL24R 00:0A:9F:00:D4:C1
3.2.1.28
10.21.66.248 ADMS.04.01 BAS-ADSL24R 00:0A:9F:00:D4:D1
3.2.1.28
10.21.67.252 ADMS.05.01 BAS-ADSL24R 00:0A:9F:00:E5:DA
3.2.1.28
Desired output of BASIP.list:
0a1541fc
0a1542fc
0a1542fa
0a1542f8
0a1543fc
------------------------------
Date: Thu, 04 Mar 2010 08:21:47 -0600
From: Don Pich <dpich@polartel.com>
Subject: Re: Return text left of first tab
Message-Id: <So2dnSFLTeBmXBLWnZ2dnUVZ_hYAAAAA@polarcomm.com>
After the 'my ($line) = $_;' line, I need to eliminate everything after
and including the first tab of a line in Pannaway.txt. Then send what
is left (IP Address column only) into the my@values to convert the
dotted quad ip address into a hex representation of the ip.
IF the line contains BAS-ADSL!
------------------------------
Date: Thu, 04 Mar 2010 08:21:34 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Return text left of first tab
Message-Id: <aelvo518ckejc7dc7fbgug0n2jpqlokt15@4ax.com>
Don Pich <dpich@polartel.com> wrote:
> Here is my script as it stands right now:
Running your script I get an error message:
Global symbol "$data" requires explicit package name at
C:\Users\jue\tmp\t.pl line 13.
Execution of C:\Users\jue\tmp\t.pl aborted due to compilation errors.
So I assume this is your problem. It is very easy to fix: you declare
and define $line in line 11 but are accessing $data in line 13 where I
think you meant to access the data that you extracted in line 11.
Just change either variable name to the other and you should be good to
go.
Please also see below for some additional comments on your code.
>After the 'my ($line) = $_;' line, I need to eliminate everything after
>and including the first tab of a line in Pannaway.txt. Then send what is
>left (IP Address column only) into the my@values to convert the dotted
>quad ip address into a hex representation of the ip.
>
[...]
>while (<INFILE>){
> if (/BAS-ADSL/)
Many, many people will do exactly the same thing, it's almost a Perl
idiom, but arguably I find
if (index($_, 'BAS-ADSL') >= 0)
more suitable because it neither requires escaping of RE-special
characters nor will it launch the big RE engine.
> {
> my ($line) = $_;
> my @values = split('\.', $data);
These 2 lines above contain the reason for the error message you are
getting.
> foreach my $val (@values) {
> $val = sprintf("%02x", $val);
> printf OUTFILE $val;
> }
> print OUTFILE "\n";
While I can see what you are trying to do in the body of the if() clause
IMO it is premature (you didn't isolate the IP yet) as well as misguided
(why run your own code to convert the decimal IP to hex?).
Step 1: isolate that IP address:
my $ip_addr = (split(/\t/)[0];
Step 2: convert the IP address to hex using the Net::IP module and ...
Step 3: print it
my $ip = new Net::IP ($ip_addr)
or die "Error converting IP-Adress:$!";
print OUTFILE $ip->hexip();
jue
------------------------------
Date: Thu, 4 Mar 2010 08:24:10 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Return text left of first tab
Message-Id: <abd93103-7b0b-404b-bf6a-a07261f31349@y17g2000yqd.googlegroups.com>
On Mar 4, 9:15=A0am, Don Pich <dp...@polartel.com> wrote:use strict;
use warnings;
my @ips;
while (<DATA>)
{
next unless $_ =3D~ /^\d/;
chomp;
my ($ip, $name, $type, $mac, $firm) =3D split;
my @ip =3D split /\./, $ip;
my $val;
foreach my $i (@ip) { $val .=3D sprintf "%02x", $i; }
push @ips, $val;
}
print "@ips\n";
__DATA__
IP Address Name Type MAC Address
Firmware
10.21.65.252 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
3.2.1.28
10.21.66.252 ADMS.02.01 BAS-ADSL24R 00:0A:9F:00:D4:A5
3.2.1.28
10.21.66.250 ADMS.03.01 BAS-ADSL24R 00:0A:9F:00:D4:C1
3.2.1.28
10.21.66.248 ADMS.04.01 BAS-ADSL24R 00:0A:9F:00:D4:D1
3.2.1.28
10.21.67.252 ADMS.05.01 BAS-ADSL24R 00:0A:9F:00:E5:DA
3.2.1.28
------------------------------
Date: Thu, 04 Mar 2010 11:05:33 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Return text left of first tab
Message-Id: <slrnhovprp.jh3.tadmc@tadbox.sbcglobal.net>
Don Pich <dpich@polartel.com> wrote:
>
> After the 'my ($line) = $_;' line, I need to eliminate everything after
> and including the first tab of a line in Pannaway.txt. Then send what
> is left (IP Address column only) into the my@values to convert the
> dotted quad ip address into a hex representation of the ip.
>
> IF the line contains BAS-ADSL!
You should try and write a short and complete program that we
can run that illustrates your problem.
Have you seen the Posting Guidelines that are posted here frequently?
Anyway, this ought to do it (if I'm understanding your blurry "spec"):
--------------------
#!/usr/bin/perl
use warnings;
use strict;
my $line = "10.21.65.252\tADMS.01.01\tBAS-ADSL24R\t00:0A:9F:00:D4:75\n";
my @values;
push @values, $line =~ /([^\t]+)/ if $line =~ /BAS-ADSL/;
print "@values\n";
--------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Thu, 04 Mar 2010 09:36:19 -0800
From: sln@netherlands.com
Subject: Re: Return text left of first tab
Message-Id: <25rvo5db0esgti2bgpmvdb8bb93dmhr54t@4ax.com>
On Thu, 04 Mar 2010 08:15:12 -0600, Don Pich <dpich@polartel.com> wrote:
>After the 'my ($line) = $_;' line, I need to eliminate everything after
>and including the first tab of a line in Pannaway.txt. Then send what is
>left (IP Address column only) into the my@values to convert the dotted
>quad ip address into a hex representation of the ip.
>
An assumption, this regex adds some further qualifying boundry conditions.
If learning regex's, you might want to break down the example
as an exercise.
-sln
use strict;
use warnings;
while (<DATA>)
{
if (/^((?:\d+\.?){4,6})[.:\d]*?\t.*BAS-ADSL/) {
my @ipparts = split('\.', $1);
printf ('%02x'x scalar(@ipparts) ."\n", @ipparts);
}
}
__DATA__
IP Address Name Type MAC Address
Firmware
10.21.65.252.5.4.3 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
10.21.1.2:1280 ADMS.01.01 BAS-ADSL24R 00:0A:9F:00:D4:75
3.2.1.28
10.21.66.252 ADMS.02.01 BAS-ADSL24R 00:0A:9F:00:D4:A5
3.2.1.28
10.21.66.250 ADMS.03.01 BAS-ADSL24R 00:0A:9F:00:D4:C1
3.2.1.28
10.21.66.248 ADMS.04.01 BAS-ADSL24R 00:0A:9F:00:D4:D1
3.2.1.28
10.21.67.252 ADMS.05.01 BAS-ADSL24R 00:0A:9F:00:E5:DA
3.2.1.28
------------------------------
Date: 4 Mar 2010 18:10:28 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Return text left of first tab
Message-Id: <slrnhovtsk.5j.glennj@smeagol.ncf.ca>
At 2010-03-04 11:21AM, "Jürgen Exner" wrote:
> Don Pich <dpich@polartel.com> wrote:
[...]
> >while (<INFILE>){
> > if (/BAS-ADSL/)
>
> Many, many people will do exactly the same thing, it's almost a Perl
> idiom, but arguably I find
> if (index($_, 'BAS-ADSL') >= 0)
> more suitable because it neither requires escaping of RE-special
> characters nor will it launch the big RE engine.
[...]
> Step 2: convert the IP address to hex using the Net::IP module and ...
> Step 3: print it
>
> my $ip = new Net::IP ($ip_addr)
> or die "Error converting IP-Adress:$!";
> print OUTFILE $ip->hexip();
Premature optimization. You use index() over m// due to concerns about
the performance of regex matching, but then you'll go load a 60+ kB
module that uses plenty of regexes.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Thu, 04 Mar 2010 12:55:04 -0600
From: Don Pich <dpich@polartel.com>
Subject: Re: Return text left of first tab
Message-Id: <So2dnV9LTeCVnw3WnZ2dnUVZ_hYAAAAA@polarcomm.com>
You know what? My completely ugly script actually did what it was
supposed to. This was a one time shot and probably will not have to run
this again in the near future. So I think I will call off the hunt on
getting this going.
I'm VERY new at trying to use Perl. I've used other programing languages
before. But I'm definitely in my infancy at trying to understand.
If I post to this forum again, I will try to be more specific as not to
cause confusion.
Thanks to all who helped me as far as they did!!!
------------------------------
Date: Thu, 4 Mar 2010 06:39:36 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: tape rotations and tape autoloaders
Message-Id: <6a0d49f0-78e2-4e1c-9f0f-b7580858a3c7@15g2000yqi.googlegroups.com>
Hi everyone,
I have a tape autoloader with 8 tapes. The tapes are labeled monday,
tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
My backup script needs to be modified to load the correct tape each
friday. A copy of the existing script can be found here:
http://bobotheclown.org/scripts/compperl
Here is the code I have written so far:
#!/usr/bin/perl
use strict;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
my $tapenumber = --$wday;
my $filename = "/backup/scripts/week_of_month";
if ($wday == 5) {
open FH15,'+<', $filename or die "Could not open $filename: $!\n";
my @weeknumber = <FH15>;
}
my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";
I am presently planning to incriment the week number in a txt file
until it reaches 4 and then start over. This seems fail to me. The
text file may be deleted, and the rotation will be lost. It is also a
lot of code to write.
Can anyone suggest a more intelligent alternative for finding the 1st,
2nd, 3rd, and 4th friday relative to the first time the script ever
ran?
------------------------------
Date: Thu, 4 Mar 2010 08:19:42 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <6dcd1648-99e1-4562-9183-3e9d6a19b47d@19g2000yqu.googlegroups.com>
On Mar 4, 9:39=A0am, "Nix!" <rocky.allen....@gmail.com> wrote:
> Hi everyone,
>
> I have a tape autoloader with 8 tapes. =A0The tapes are labeled monday,
> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
>
> My backup script needs to be modified to load the correct tape each
> friday. =A0A copy of the existing script can be found here:http://bobothe=
clown.org/scripts/compperl
>
> Here is the code I have written so far:
>
> #!/usr/bin/perl
>
> use strict;
>
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =3D
> localtime(time);
> my $tapenumber =3D --$wday;
> my $filename =3D "/backup/scripts/week_of_month";
>
> if ($wday =3D=3D 5) {
>
> open FH15,'+<', $filename or die "Could not open $filename: $!\n";
> my @weeknumber =3D <FH15>;
>
> }
>
> my $loadtape =3D "mtx -f /dev/sg17 load $tapenumber";
> print "$loadtape\n";
> my $unloadtape =3D "mtx -f /dev/sg17 unload $tapenumber";
> print "$unloadtape\n";
>
> I am presently planning to incriment the week number in a txt file
> until it reaches 4 and then start over. =A0This seems fail to me. =A0The
> text file may be deleted, and the rotation will be lost. =A0It is also a
> lot of code to write.
>
> Can anyone suggest a more intelligent alternative for finding the 1st,
> 2nd, 3rd, and 4th friday relative to the first time the script ever
> ran?
heres what I did:
#!/usr/bin/perl
use strict;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =3D
localtime(time);
my $tapenumber =3D --$wday;
my $filename =3D "/backup/scripts/week_of_month";
if ($wday =3D=3D 5) {
open FH15,'<', $filename or die "Could not open $filename: $!
\n";
my @weeknumber =3D <FH15>;
my $weekscalar =3D $weeknumber[0];
close FH15;
if ($weekscalar =3D=3D 1) {
$tapenumber =3D 5;
$weekscalar++;
} elsif ($weekscalar =3D=3D 2) {
$tapenumber =3D 6;
$weekscalar++;
} elsif ($weekscalar =3D=3D 3) {
$tapenumber =3D 7;
$weekscalar++;
} elsif ($weekscalar =3D=3D 4) {
$tapenumber =3D 8;
$weekscalar =3D 1;
}
open FH15,'>', $filename or die "Could not open $filename: $!
\n";
print FH15 $weekscalar;
close FH15;
}
my $loadtape =3D "mtx -f /dev/sg17 load $tapenumber";
print "$loadtape\n";
my $unloadtape =3D "mtx -f /dev/sg17 unload $tapenumber";
print "$unloadtape\n";
Its ugly but it works, and I can work on something else now. :)
------------------------------
Date: Thu, 04 Mar 2010 10:40:25 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <878wa8kpl2.fsf@lifelogs.com>
On Thu, 4 Mar 2010 06:39:36 -0800 (PST) "Nix!" <rocky.allen.ats@gmail.com> wrote:
N> I have a tape autoloader with 8 tapes. The tapes are labeled monday,
N> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
...
N> Can anyone suggest a more intelligent alternative for finding the 1st,
N> 2nd, 3rd, and 4th friday relative to the first time the script ever
N> ran?
If you have a way of finding out what's on each tape (even if it's just
a tape ID) and keeping track, that's a much better way. Then you can
just load the Friday tape with the oldest data. So I would keep a map
of (tape ID => last backup done) and then your script can easily find
the right ID it needs for today.
I would also consider a better backup solution. This is easily handled
by modern backup systems.
Ted
------------------------------
Date: Thu, 04 Mar 2010 10:50:10 -0600
From: Don Piven <spamtrap@piven.net>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <d9ednaBFJJVeeRLWnZ2dnUVZ_judnZ2d@speakeasy.net>
Nix! wrote:
> Hi everyone,
>
> I have a tape autoloader with 8 tapes. The tapes are labeled monday,
> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
> [...]
> I am presently planning to incriment the week number in a txt file
> until it reaches 4 and then start over. This seems fail to me. The
> text file may be deleted, and the rotation will be lost. It is also a
> lot of code to write.
Deleted by who? Don't forget that in order to control your changer, you
need to be able to write to the device. Practically speaking, this
means your script has to be executed by the owner of the changer device,
or a user who is a member of a group that has write access to the
device. On Linux, this usually means that you have to run mtx as root,
or your login id needs to be a member of the "tape" group. (YMMV.) So,
why not just restrict access to that text file using the same permissions?
I suppose that if you wanted to be independent and not depend on
anything in or on the filesystem that could be modified, you could take
the number of days since the epoch, divide by 7 to get number of weeks
since the epoch, and use that modulo 4 for your arbitrary week number.
(This might mean your first Friday backup would use "Friday 3", though.)
You could do something similar using the ctime of your script file as
the baseline, but that's subject to breakage as well if you happen to
copy or move the script file.
Out of curiosity, are you just planning on rotating those four Friday
tapes without regard to month boundaries? If you want "Friday 1" to
correspond to the first Friday of the month, better rethink your
rotation strategy because it'll bite you on the butt this upcoming April
30, which is the 5th Friday of the month.
------------------------------
Date: Thu, 4 Mar 2010 10:45:27 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <a4f9d33c-c90c-44e1-bc1a-1991be2c4fae@q21g2000yqm.googlegroups.com>
On Mar 4, 11:50=A0am, Don Piven <spamt...@piven.net> wrote:
> Nix! wrote:
> > Hi everyone,
>
> > I have a tape autoloader with 8 tapes. =A0The tapes are labeled monday,
> > tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
> > [...]
> > I am presently planning to incriment the week number in a txt file
> > until it reaches 4 and then start over. =A0This seems fail to me. =A0Th=
e
> > text file may be deleted, and the rotation will be lost. =A0It is also =
a
> > lot of code to write.
>
> Deleted by who? =A0Don't forget that in order to control your changer, yo=
u
> need to be able to write to the device. =A0Practically speaking, this
> means your script has to be executed by the owner of the changer device,
> or a user who is a member of a group that has write access to the
> device. =A0On Linux, this usually means that you have to run mtx as root,
> or your login id needs to be a member of the "tape" group. =A0(YMMV.) =A0=
So,
> why not just restrict access to that text file using the same permissions=
?
>
> I suppose that if you wanted to be independent and not depend on
> anything in or on the filesystem that could be modified, you could take
> the number of days since the epoch, divide by 7 to get number of weeks
> since the epoch, and use that modulo 4 for your arbitrary week number.
> (This might mean your first Friday backup would use "Friday 3", though.)
> =A0 You could do something similar using the ctime of your script file as
> the baseline, but that's subject to breakage as well if you happen to
> copy or move the script file.
>
> Out of curiosity, are you just planning on rotating those four Friday
> tapes without regard to month boundaries? =A0If you want "Friday 1" to
> correspond to the first Friday of the month, better rethink your
> rotation strategy because it'll bite you on the butt this upcoming April
> 30, which is the 5th Friday of the month.
I use the grandfather son strategy modified for 5 days a week instead
of 7. That is why I didnt want to use dates as a key. Over the four
friday rotation, at the end of 365 days I will have used 20 tapes + 1
annual (remembering that I never overwrite a friday 4) It doesnt
really matter when I begin as it is based on 365 days.
By doing it this way I will be able to recover from any day this week,
any week this month, any month this year, or any year since the sytem
has been in operation.
Thank you very much for your advice.
------------------------------
Date: Thu, 4 Mar 2010 10:46:23 -0800 (PST)
From: "Nix!" <rocky.allen.ats@gmail.com>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <01601c67-f69f-4f12-b462-3cec81c029fa@b30g2000yqd.googlegroups.com>
On Mar 4, 11:40=A0am, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Thu, 4 Mar 2010 06:39:36 -0800 (PST) "Nix!" <rocky.allen....@gmail.com=
> wrote:
>
> N> I have a tape autoloader with 8 tapes. =A0The tapes are labeled monday=
,
> N> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
>
> ...
>
> N> Can anyone suggest a more intelligent alternative for finding the 1st,
> N> 2nd, 3rd, and 4th friday relative to the first time the script ever
> N> ran?
>
> If you have a way of finding out what's on each tape (even if it's just
> a tape ID) and keeping track, that's a much better way. =A0Then you can
> just load the Friday tape with the oldest data. =A0So I would keep a map
> of (tape ID =3D> last backup done) and then your script can easily find
> the right ID it needs for today.
>
> I would also consider a better backup solution. =A0This is easily handled
> by modern backup systems.
>
> Ted
Great idea Ted. Im gonna chase this down. Sorry everyone for getting
off perl code.
------------------------------
Date: Thu, 4 Mar 2010 19:47:51 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <slrnhp002p.9pk.hjp-usenet2@hrunkner.hjp.at>
On 2010-03-04 16:19, Nix! <rocky.allen.ats@gmail.com> wrote:
> On Mar 4, 9:39 am, "Nix!" <rocky.allen....@gmail.com> wrote:
>> I have a tape autoloader with 8 tapes. The tapes are labeled monday,
>> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
>>
>> My backup script needs to be modified to load the correct tape each
>> friday. A copy of the existing script can be found here:http://bobotheclown.org/scripts/compperl
[...]
>> I am presently planning to incriment the week number in a txt file
>> until it reaches 4 and then start over. This seems fail to me. The
>> text file may be deleted, and the rotation will be lost. It is also a
>> lot of code to write.
>>
>> Can anyone suggest a more intelligent alternative for finding the 1st,
>> 2nd, 3rd, and 4th friday relative to the first time the script ever
>> ran?
>
>
>
> heres what I did:
>
> #!/usr/bin/perl
>
> use strict;
use warnings;
> my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> localtime(time);
> my $tapenumber = --$wday;
> my $filename = "/backup/scripts/week_of_month";
>
> if ($wday == 5) {
>
> open FH15,'<', $filename or die "Could not open $filename: $!
> \n";
Use lexical filehandles:
open my $fh15, '<', $filename or die "Could not open $filename: $!";
(and find a better name than "$fh15", e.g. $week_fh)
> my @weeknumber = <FH15>;
> my $weekscalar = $weeknumber[0];
These two lines can be replaced with
my $weekscalar = <FH15>;
but you should also add a
chomp($weekscalar);
to remove the trailing newline (and avoid a warning).
> close FH15;
>
> if ($weekscalar == 1) {
> $tapenumber = 5;
> $weekscalar++;
> } elsif ($weekscalar == 2) {
> $tapenumber = 6;
> $weekscalar++;
> } elsif ($weekscalar == 3) {
> $tapenumber = 7;
> $weekscalar++;
> } elsif ($weekscalar == 4) {
> $tapenumber = 8;
> $weekscalar = 1;
> }
This whole if/elsif block can be replaced with:
$tapenumber = $weekscalar + 4;
$weekscalar = $weekscalar % 4 + 1;
> open FH15,'>', $filename or die "Could not open $filename: $!
> \n";
> print FH15 $weekscalar;
> close FH15;
> }
>
> my $loadtape = "mtx -f /dev/sg17 load $tapenumber";
> print "$loadtape\n";
> my $unloadtape = "mtx -f /dev/sg17 unload $tapenumber";
> print "$unloadtape\n";
>
>
> Its ugly but it works, and I can work on something else now. :)
------------------------------
Date: Thu, 4 Mar 2010 19:55:32 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: tape rotations and tape autoloaders
Message-Id: <slrnhp00h4.9pk.hjp-usenet2@hrunkner.hjp.at>
On 2010-03-04 16:50, Don Piven <spamtrap@piven.net> wrote:
> Nix! wrote:
>> Hi everyone,
>>
>> I have a tape autoloader with 8 tapes. The tapes are labeled monday,
>> tues, wed, thurs, friday 1, friday 2, friday 3, and friday 4.
>> [...]
>> I am presently planning to incriment the week number in a txt file
>> until it reaches 4 and then start over. This seems fail to me. The
>> text file may be deleted, and the rotation will be lost. It is also a
>> lot of code to write.
[...]
> I suppose that if you wanted to be independent and not depend on
> anything in or on the filesystem that could be modified, you could take
> the number of days since the epoch, divide by 7 to get number of weeks
> since the epoch, and use that modulo 4 for your arbitrary week number.
Alternatively you could use the number of the week in the current year:
$tapenumber = strftime("%V", localtime) % 4;
However, every few years the first backup of the year will overwrite the
last backup of the previous year (when the last week is week 53, not
week 52), so your method is probably preferable.
hp
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2851
***************************************