[30156] in Perl-Users-Digest
Perl-Users Digest, Issue: 1399 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 27 18:09:41 2008
Date: Thu, 27 Mar 2008 15:09:06 -0700 (PDT)
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, 27 Mar 2008 Volume: 11 Number: 1399
Today's topics:
Re: BEGIN, INIT etc... <pgodfrin@gmail.com>
Re: BEGIN, INIT etc... <noreply@gunnar.cc>
Copy multiples files to a single file in seperate pages <techrepository@gmail.com>
Re: Copy multiples files to a single file in seperate p <willem@stack.nl>
Re: Copy multiples files to a single file in seperate p <smallpond@juno.com>
Re: get rid of non xml compliant lines from a file <szrRE@szromanMO.comVE>
Re: Operator ->() <noreply@gunnar.cc>
Re: Pattern matching <hjp-usenet2@hjp.at>
Re: perl on pc 104 <test@example.com>
Re: perl on pc 104 <test@example.com>
Re: perl on pc 104 <john@castleamber.com>
Re: Readline using foreach and while <hjp-usenet2@hjp.at>
Re: Readline using foreach and while <hjp-usenet2@hjp.at>
Re: ssh ssh <jameslockie@mail.com>
Re: ssh ssh <jameslockie@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 Mar 2008 11:36:28 -0700 (PDT)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: BEGIN, INIT etc...
Message-Id: <08cf1015-ea47-4a5b-99f3-cdf5ea7933af@i12g2000prf.googlegroups.com>
On Mar 27, 12:00 pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "d" == dummy <du...@phony.info> writes:
>
> d> On Thu, 27 Mar 2008 03:26:31 GMT, Uri Guttman <u...@stemsystems.com>
>
> d> wrote:
>
> >> they are commonly used when you need to do something as soon as that
> >> block of code is parsed (BEGIN) or when the program is exiting
> >> (END). and the above rule applies as you don't know when you need or not
> >> need them so don't bother to learn them yet. once you get into perl
> >> deeper you will know more about initialization, compile vs runtime and
> >> destruction. but now you don't know those so ignore BEGIN/END until you
> >> need to learn them.
> >>
> >> uri
>
> d> You don't need to know it until you know it? How does that work?
> d> Something like not learning how to drive on ice until after a fatal
> d> skid?
>
> no, you learn to drive on ice only after you have mastered general
> driving and have a need or desire to learn more. most newbies have no
> need for BEGIN/END and so don't need to know about them. as they learn
> more perl and get to know modules, scoping and compile vs runtime then
> those concepts will help them learn how and when to use BEGIN/END. my
> point is that they are not needed by newbies and shouldn't be taught as
> they will just confuse them.
>
> d> I also would like to learn this topic in advance of need.
>
> do you write modules? do you have subtle initialization or destruction
> needs? if not, you don't need to learn them yet. read perlmod more times
> and if you don't grasp the concepts then get a good perl book. i can
> explain them but it would require a decent sized post or small
> article. it makes a good topic and i may do it one day. i already have
> seen a need for a definitive article on lists vs arrays and i have been
> writing it in my head. but too many things are higher priority for me
> now to do that.
>
> uri
>
> --
> Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com--
> ----- Perl Code Review , Architecture, Development, Training, Support ------
> --------- Free Perl Training ---http://perlhunter.com/college.html---------
> --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com---------
slightly off topic, but - yes I do write modules - only for personal
consumption and very limited needs. Basically 'cause I don't want to
repeat the same exact code in every perl program I write. While not
exactly a newbie to Perl, I probably still qualify as such since most
of my perl code has been very utilitarian - mostly as replacement for
shell scripts. So my needs are very basic as is my experience and
exposure.
So how prevalent is Perl in the commercial world? Do people actually
have full-time jobs writing perl modules? Do people use perl to write
software like Microsoft Office or Quest Software's Toad? Or perhaps
BMC Patrol or CA Univision? What is it mostly used for?
regards,
pg
------------------------------
Date: Thu, 27 Mar 2008 20:27:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: BEGIN, INIT etc...
Message-Id: <652aqpF2ckif2U1@mid.individual.net>
Joost Diepenmaat wrote:
> pgodfrin <pgodfrin@gmail.com> writes:
>> I also came across a glitch when using CGI and DBI modules, where some
>> variables lose scope when the BEGIN code block is completed (which is
>> clearly alluded to in perlmod). But in plain old Perl I can still
>> refer to variables assigned in BEGIN in later parts of the code. So
>> there is a corollary between these code blocks and scope. It would
>> seem to me that a good discussion about scope (perldoc ???) is in
>> order too...
>
> I think you're mistaken, that always happens:
>
> $ perl -Mstrict -w -e'BEGIN { my $f = 1;} print $f'
> Global symbol "$f" requires explicit package name at -e line 1.
So you'd better declare the variable outside the BEGIN block.
$ perl -Mstrict -w -e'my $f; BEGIN {$f=1} print "$f\n"'
1
$
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 27 Mar 2008 12:30:30 -0700 (PDT)
From: Wg <techrepository@gmail.com>
Subject: Copy multiples files to a single file in seperate pages..
Message-Id: <8825ad17-48bf-48fc-9a85-d543bf0e3024@u69g2000hse.googlegroups.com>
Hi,
Trying to understand if we have a mechanism to copy multiple files
( txt files ) to a single file (say abc.txt) with each file residing
in single page. Each input file is large enough to fit into a single
page. I have tried using perl format's like $- and other mechanism in
vain.
Is there a way to insert a page character after reading each file or
seperate each file into different pages? Any suggestions other than
adding "\n" is greatly appreciated..
The goal of this exercise is to convert the single file (abc.txt) to
postscript file and then to pdf using ps2pdf utility.. Can't use cpan
modules as some of these input files contain unicode characters...
This post is more verbose but repeated as the earlier post didn't
appear in the group..
Thanks for your patience,
-Wg.
------------------------------
Date: Thu, 27 Mar 2008 19:34:44 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Copy multiples files to a single file in seperate pages..
Message-Id: <slrnfuntmk.2ash.willem@snail.stack.nl>
Wg wrote:
) Hi,
)
) Trying to understand if we have a mechanism to copy multiple files
) ( txt files ) to a single file (say abc.txt) with each file residing
) in single page. Each input file is large enough to fit into a single
) page. I have tried using perl format's like $- and other mechanism in
) vain.
)
) Is there a way to insert a page character after reading each file or
) seperate each file into different pages? Any suggestions other than
) adding "\n" is greatly appreciated..
)
) The goal of this exercise is to convert the single file (abc.txt) to
) postscript file and then to pdf using ps2pdf utility.. Can't use cpan
) modules as some of these input files contain unicode characters...
What utility are you using to generate the postscript file ?
That should have some kind of documentation that describes what it uses
to separate pages.
If it doesn't, bad luck. You can probably generate several postscript
files, one for each page, and then use a simple utility to put those
together into one postscript file, or even directly into a pdf.
Or if you want to do it by hand, just generate the postscript directly
from the perl script. That shouldn't be too hard, actually.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Thu, 27 Mar 2008 15:00:13 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Copy multiples files to a single file in seperate pages..
Message-Id: <abfc057b-2ea3-44a9-95fc-fedb00e88b09@e67g2000hsa.googlegroups.com>
On Mar 27, 3:30 pm, Wg <techreposit...@gmail.com> wrote:
> Hi,
>
> Trying to understand if we have a mechanism to copy multiple files
> ( txt files ) to a single file (say abc.txt) with each file residing
> in single page. Each input file is large enough to fit into a single
> page. I have tried using perl format's like $- and other mechanism in
> vain.
>
> Is there a way to insert a page character after reading each file or
> seperate each file into different pages? Any suggestions other than
> adding "\n" is greatly appreciated..
>
> The goal of this exercise is to convert the single file (abc.txt) to
> postscript file and then to pdf using ps2pdf utility.. Can't use cpan
> modules as some of these input files contain unicode characters...
>
> This post is more verbose but repeated as the earlier post didn't
> appear in the group..
>
> Thanks for your patience,
> -Wg.
You can try inserting form feed = chr(12) which some conversion
utilities will interpret as a page break according to the ASCII
chart on my pocket protector.
--S
------------------------------
Date: Thu, 27 Mar 2008 11:55:27 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: get rid of non xml compliant lines from a file
Message-Id: <fsgqj101n4d@news2.newsguy.com>
Ben Morrow wrote:
> Quoth Mr_Noob <gniagnia@gmail.com>:
>>
>> I try to write a perl script that would delete all non xml complient
>> lines (ie beginning with "<" and ending ">").
>> Here is what i succeded to put down so far :
>>
>> sub delete_non_xml_lines
>> {
>> my $search = new File::List($xmldir);
>
> Indirect object syntax (new Foo) is unreliable and can parse
> incorrectly. Use
I don't deny that that is god advise, though I personally have never had
any problems creating an option using "my $o = new Foo(...);" as opposed
to "my $o = Foo->new(...);"... as long as you know the potential
problems, they are easy to avoid. Namely, watch those parens :-)
--
szr
------------------------------
Date: Thu, 27 Mar 2008 20:35:27 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Operator ->()
Message-Id: <652ba5F2b43vdU1@mid.individual.net>
Subra wrote:
[ exactly the same question as was posted to the beginners list a few
minutes earlier ]
DO NOT DO THAT !!!
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 27 Mar 2008 20:49:44 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Pattern matching
Message-Id: <slrnfunuit.21p.hjp-usenet2@hrunkner.hjp.at>
On 2008-03-27 04:32, Deepan Perl XML Parser <deepan.17@gmail.com> wrote:
> On Mar 26, 5:31 pm, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
>> On 2008-03-26 04:00, Deepan Perl XML Parser <deepan...@gmail.com> wrote:
>> > On Mar 25, 7:13 pm, Lawrence Statton <yankeeinex...@gmail.com> wrote:
>> >> Deepan Perl XML Parser <deepan...@gmail.com> writes:
>>
>> >> > No i am writing my own XML parser.
>>
>> >> Don't. There are many good XML parsers out there, the world doesn't
>> >> need another one.
>>
>> > Okay then can you name any parsers that would get the CDATA section?
>>
>> Which one doesn't?
>>
>> LibXML certainly does (I just tested it). I think expat does, too.
>> I have my doubts about the pure perl XML parser, but that has a lot of
>> other problems too and shouldn't be used.
>
> This one XML::Parser doesn't. It just signals you as CDATA starts and
> ends here. It is not possible to get the data which is present using
> this.
Works for me:
chronos:/wsrdb/users/hjp/tmp 20:47 112% cat foo.xml
<script>
<![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
]]>
</script>
chronos:/wsrdb/users/hjp/tmp 20:47 113% cat foo
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
$x = XMLin($ARGV[0]);
print Dumper $x;
chronos:/wsrdb/users/hjp/tmp 20:47 114% export XML_SIMPLE_PREFERRED_PARSER=XML::Parser
chronos:/wsrdb/users/hjp/tmp 20:47 115% ./foo foo.xml
$VAR1 = '
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1;
}
else
{
return 0;
}
}
';
hp
------------------------------
Date: Thu, 27 Mar 2008 18:31:45 GMT
From: Ron Eggler <test@example.com>
Subject: Re: perl on pc 104
Message-Id: <lKRGj.751$9X3.685@edtnps82>
Ben Morrow wrote:
>
> Quoth Ron Eggler <test@example.com>:
>>
>> I need to get perl5 on our little pc104 (with goede) system in order to
>> get ssh-keygen( openSSH) - which depends on openSSL which depends on
>> perl5 - running.
>> When I'm trying to compile (configure) it, I get this messages:
>> [shell]
>> I used the command:
>>
>> cc -o
>> try -O2 -fno-strict-aliasing -pipe -I/usr/local/include -L/usr/local/lib
>> try.c -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
>> ./try
>>
>> and I got the following output:
>>
>> /usr/lib/gcc/i586-linux-uclibc/3.4.4/../../../libdb.so: undefined
>> reference to `pthread_condattr_setpshared'
> <snip>
>>
>> Any ideawhat I would be doing wrongly and what that exactly is, as you
>> can see, i made a find on the bottom and i do have the libdb.so available
>> in /usr/lib.
>
> The problem is not libdb.so, it's that libdb.so requires the pthread
> functions, which aren't getting loaded. Do you have a version of
> libdb.so which doesn't require threads, and can you persuade Configure
> to use it?
>
> Alternatively, can you Configure perl with -Duseithreads? I wouldn't
> normally recommend this on a Unix machine (perl threads are practically
> useless when you have fork(2)), but it may be an easy way to pull the
> thread libraries in.
>
> Otherwise, you may have more luck asking perl5-porters@perl.org: they
> are the people who maintain perl, and they will certainly be interested
> in situations where perl won't configure.
>
> Ben
Alright, ./Configure -Duseithreads went well withou doing anything else to
pthread libraries.
BUT I get this on make test or make install:
[shell]
NEMS perl-5.10.0 # make test
make: *** No rule to make target `/usr/include/bits/errno_values.h', needed
by `miniperlmain.o'. Stop.
NEMS perl-5.10.0 # make install
make install.perl install.man STRIPFLAGS= DESTDIR=""
make[1]: Entering directory `/uc/home/ron/software/perl-5.10.0'
make[1]: *** No rule to make target `/usr/include/bits/errno_values.h',
needed by `miniperlmain.o'. Stop.
make[1]: Leaving directory `/uc/home/ron/software/perl-5.10.0'
make: *** [install] Error 2
[/shell]
Not really sure wht this means and if this relates to the pthread problem i
had before.
--
chEErs roN
------------------------------
Date: Thu, 27 Mar 2008 18:32:32 GMT
From: Ron Eggler <test@example.com>
Subject: Re: perl on pc 104
Message-Id: <4LRGj.752$9X3.609@edtnps82>
John Bokma wrote:
> Ron Eggler <test@example.com> wrote:
>
> [..]
>
>> /usr/lib/gcc/i586-linux-uclibc/3.4.4/../../../libdb.so: undefined
>> reference to `pthread_mutexattr_setpshared'
>> /usr/lib/gcc/i586-linux-uclibc/3.4.4/../../../libdb.so: undefined
>> reference to `pthread_mutexattr_init'
>> /usr/lib/gcc/i586-linux-uclibc/3.4.4/../../../libdb.so: undefined
>
> [..]
>
>> Any ideawhat I would be doing wrongly and what that exactly is, as you
>> can see, i made a find on the bottom and i do have the libdb.so
>> available in /usr/lib.
>
> But do you have pthread.so (I assume it's called like that).
>
> (Unless I am not entirely awake and read the messages wrong...)
I'm not sure what i would need to install to get this problem with pthread
resolved... :o
--
chEErs roN
------------------------------
Date: 27 Mar 2008 19:16:44 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: perl on pc 104
Message-Id: <Xns9A6E8716233FBcastleamber@130.133.1.4>
Ron Eggler <test@example.com> wrote:
[..]
> make: *** No rule to make target `/usr/include/bits/errno_values.h',
> needed by `miniperlmain.o'. Stop.
[..]
Sounds to me like errno_values.h is missing.
--
John
http://johnbokma.com/perl/
------------------------------
Date: Thu, 27 Mar 2008 21:26:50 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Readline using foreach and while
Message-Id: <slrnfuo0oc.21p.hjp-usenet2@hrunkner.hjp.at>
On 2008-03-27 04:45, szr <szrRE@szromanMO.comVE> wrote:
> nolo contendere wrote:
>> Provably untrue. See Ben's example. I'll restate the concept below.
>>
>> my @ary = qw/a b c/;
>> # for (@ary, ()) {
>> # for ( (), @ary ) {
>> for ( @ary ) {
>> push @ary, 'd' if /c/;
>> print;
>> }
>>
>> ...
>>
>> only the uncommented 'for' line prints a 'd' at the end. so what you
>> say MAY be true if LIST is ONLY an array.
>
> Isn't that because the two commented one are two lists being combined
> into a new list, and it's *that* new list that's being iterated over, so
> even if you add to @ary, it doesn't change the "new list", which is just
> that, a new list created at the start of the loop before iterating
> begins - therefore the values of the new list are set and @ary has
> nothing to do with it after the create of the "new list."
Yes. But the same should be true for
for (@ary) {
...
}
for() expects a list, the list is constructed from the elements of @ary.
If you modify @ary after the list is constructed, the list shouldn't be
affected, but it is. I think Ben Morrow is right here: This smells like
an optimization: If there is only a single array, it can be used
directly instead of creating a list from it.
hp
------------------------------
Date: Thu, 27 Mar 2008 21:36:02 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Readline using foreach and while
Message-Id: <slrnfuo19l.21p.hjp-usenet2@hrunkner.hjp.at>
On 2008-03-27 01:29, Ben Bullock <benkasminbullock@gmail.com> wrote:
> On Mar 26, 9:52 am, Ben Morrow <b...@morrow.me.uk> wrote:
>
>> > To read a file into an array use:
>>
>> > my @ary = <handle>;
>>
>> No. This reads the contents of the file into a list, and then assigns
>> that list to an array. The contents of the array are no longer anything
>> to do with the file.
>
> I'm not sure what sense you're using the word "read" here but it isn't
> the usual one.
> If I read a book, the words go into my head, but after that if I burn
> the book, then usually my head doesn't catch fire, and if I shoot
> myself in the head, then the book doesn't get a bullet hole through
> it.
>
> Similarly, in my understanding of the word "read" for computers, if I
> read a file into an array, I don't expect that deleting or altering
> the array after the "read" statement has finished will affect the
> file, and vice-versa.
I think Ben Morrow used the word "read" exactly in the sense you
described here.
What he was getting at is that
>> > my @ary = <handle>;
consists (at least conceptually) of two distinct operations:
First, the <> operator is called on handle. This reads lines from handle
and returns a list with one line per element.
Then the = operator is called which takes the list from the previous
step and assigns each element to an element of the array @ary, shrinking
or expanding @ary as needed.
The <> operator doesn't know or care what happens to the list it returns
and the = operator doesn't know or care where the list that it takes
comes from. So while the overall effect of that line is "to read a file
into an array", there is no operation which does that.
hp
------------------------------
Date: Thu, 27 Mar 2008 11:47:24 -0700 (PDT)
From: jammer <jameslockie@mail.com>
Subject: Re: ssh ssh
Message-Id: <3da92aed-972b-4902-82f2-88c5695ada87@a22g2000hsc.googlegroups.com>
On Mar 27, 1:02 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth jammer <jamesloc...@mail.com>:
>
> > I am trying to write a script that takes a list of hosts and sshs into
> > the first one and then can ssh to other ones. I can only ssh to the
> > other hosts from the first host.
>
> > Here is what I tried:
> > I think it is waiting for the ssh to the first host to finish.
>
> > I guess I could scp a partial hostlist and a program to *.domain and
> > then run the program remotely.
> > Am I on a right track?
>
> No. Step back a minute and consider how you would do this without Perl:
> what you want to end up running is
>
> ssh host1.domain ssh host2 uname -a
>
> assuming ssh is in your default PATH on host1.domain. What you actually
> end up running, here (or would if it weren't commented),
>
> > # print `ssh $line`;
>
> is
>
> ssh host1.domain
>
> with no command specified. This will give you a shell; while it would be
> possible to remote-control that shell, it's much easier to use ssh's
> ability to run a command directly. You want something like
>
> open my $HOSTLIST, '<', 'hostlist3.txt'
> or die "can't open hostlist3.txt: $!";
>
> $/ = ''; # this will read a paragraph at a time
> $\ = "\n"; # avoids needing to print it all the time
>
> while (<$HOSTLIST>) {
> my $cmd = join ' ', map "ssh $_", split /\n/;
> $cmd .= ' uname -a';
> print "executing '$cmd'";
> print `$cmd`;
> }
>
> which will cope with any number of intervening hosts automatically. Note
> that this assumes none of the items in hostlist3.txt have spaces in:
> annoyingly, there isn't a form of backticks corresponding to system
> LIST, so that would be rather harder to deal with.
>
> Ben
Here is my next attempt:
#!/bin/perl
use strict;
my $inputFile = 'hostlist3.txt';
open my $HOSTLIST, '<', $inputFile
or die "can't open hostlist: $!";
$/ = ''; # this will read a paragraph at a time
$\ = "\n"; # avoids needing to print it all the time
while (<$HOSTLIST>) {
my @hostList = split /\n/;
my $adminHost = shift( @hostList ); # first line
print 'adminHost=' . $adminHost;
my $otherHosts = join ' ', map "ssh $_ uname -a", @hostList;
my $cmd = "ssh ccn\@$adminHost $otherHosts";
print "executing '$cmd'";
print `$cmd`;
}
The problem is that I can't seem to run more than one command from
ssh.
I don't really want to open and ssh connection for each otherHosts.
What if hostlist3.txt is:
host1.domain
host2
host3
host4.domain
...
I need 'ssh host1.domain ssh host2 uname -a ssh host3 uname -a'.
I can do 'ssh host1.domain ssh host2 uname -a' and 'ssh host1.domain
ssh host3 uname -a' but I'd rather not ssh to host1.domain more than
once.
------------------------------
Date: Thu, 27 Mar 2008 12:35:10 -0700 (PDT)
From: jammer <jameslockie@mail.com>
Subject: Re: ssh ssh
Message-Id: <e665060e-b774-4312-9252-07bc2c3ed717@e67g2000hsa.googlegroups.com>
On Mar 27, 2:47 pm, jammer <jamesloc...@mail.com> wrote:
> On Mar 27, 1:02 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>
>
>
> > Quoth jammer <jamesloc...@mail.com>:
>
> > > I am trying to write a script that takes a list of hosts and sshs into
> > > the first one and then can ssh to other ones. I can only ssh to the
> > > other hosts from the first host.
>
> > > Here is what I tried:
> > > I think it is waiting for the ssh to the first host to finish.
>
> > > I guess I could scp a partial hostlist and a program to *.domain and
> > > then run the program remotely.
> > > Am I on a right track?
>
> > No. Step back a minute and consider how you would do this without Perl:
> > what you want to end up running is
>
> > ssh host1.domain ssh host2 uname -a
>
> > assuming ssh is in your default PATH on host1.domain. What you actually
> > end up running, here (or would if it weren't commented),
>
> > > # print `ssh $line`;
>
> > is
>
> > ssh host1.domain
>
> > with no command specified. This will give you a shell; while it would be
> > possible to remote-control that shell, it's much easier to use ssh's
> > ability to run a command directly. You want something like
>
> > open my $HOSTLIST, '<', 'hostlist3.txt'
> > or die "can't open hostlist3.txt: $!";
>
> > $/ = ''; # this will read a paragraph at a time
> > $\ = "\n"; # avoids needing to print it all the time
>
> > while (<$HOSTLIST>) {
> > my $cmd = join ' ', map "ssh $_", split /\n/;
> > $cmd .= ' uname -a';
> > print "executing '$cmd'";
> > print `$cmd`;
> > }
>
> > which will cope with any number of intervening hosts automatically. Note
> > that this assumes none of the items in hostlist3.txt have spaces in:
> > annoyingly, there isn't a form of backticks corresponding to system
> > LIST, so that would be rather harder to deal with.
>
> > Ben
>
> Here is my next attempt:
>
> #!/bin/perl
>
> use strict;
>
> my $inputFile = 'hostlist3.txt';
>
> open my $HOSTLIST, '<', $inputFile
> or die "can't open hostlist: $!";
>
> $/ = ''; # this will read a paragraph at a time
> $\ = "\n"; # avoids needing to print it all the time
>
> while (<$HOSTLIST>) {
> my @hostList = split /\n/;
>
> my $adminHost = shift( @hostList ); # first line
>
> print 'adminHost=' . $adminHost;
>
> my $otherHosts = join ' ', map "ssh $_ uname -a", @hostList;
>
> my $cmd = "ssh ccn\@$adminHost $otherHosts";
>
> print "executing '$cmd'";
> print `$cmd`;
>
> }
>
> The problem is that I can't seem to run more than one command from
> ssh.
> I don't really want to open and ssh connection for each otherHosts.
>
> What if hostlist3.txt is:
> host1.domain
> host2
> host3
>
> host4.domain
> ...
>
> I need 'ssh host1.domain ssh host2 uname -a ssh host3 uname -a'.
> I can do 'ssh host1.domain ssh host2 uname -a' and 'ssh host1.domain
> ssh host3 uname -a' but I'd rather not ssh to host1.domain more than
> once.
That is a good basis.
I am using that plus copying a script over.
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 1399
***************************************