Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Not pure perl

by monk2b (Pilgrim)
on Apr 30, 2001 at 21:42 UTC ( [id://76675]=perlquestion: print w/replies, xml ) Need Help??

monk2b has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that I wrote to get infomation about all of the linux boxes on my network. The script works ,but it is not pure perl and I can't figure out how to make it pure.Any help would be greatly appreciated
#!/usr/local/bin/perl -w use strict $file2 = "/tmp/boxinfo"; open(FILE2, ">$file2"); $file = "/export/monk2b/doc/testboxes"; open(FILE, "$file"); while(<FILE>) { my($line) = $_; chomp($line); $var1 = `rsh $line cat /proc/cpuinfo | grep "cpu MHz"` ; @par1 = split(/\s+/, $var1); $var2 = `rsh $line free | grep Mem` ; @par2 = split(/\s+/, $var2); $var3 = `rsh $line cat /etc/issue | grep Kernel` ; @par3 = split(/\s+/, $var3); print FILE2 "$line\t$par1[3]\t$par2[1]\t$par3[1]\n"; } close(FILE) close(FILE2)
Thanks monk2b learning slowly

Replies are listed 'Best First'.
Re: Not pure perl
by btrott (Parson) on Apr 30, 2001 at 22:23 UTC
    As an alternative to rsh, if you have ssh set up you might try using Net::SSH::Perl to connect to each of the hosts and execute the commands.

    (Yes, I'm biased. :)

Re: Not pure perl
by DrZaius (Monk) on Apr 30, 2001 at 22:14 UTC
    Instead of copying your code around, why not write a shell script that looks like this:
    for box in `cat /tmp/testboxes` do ssh $box 'your perl code here -- not the script file name' \ > /tmp/$box.data done
    This will execute the code on the remote server and dump the output to a file. Requires ssh keys and maybe ssh-agent.Now you can just do file opens on /proc files to get the data.

    Oh, if you want to really be pure perl, you could use Net::SSH::Perl (as another biased poster suggested) -- it may actually be cleaner because you could use a __DATA__ block for your remote perl code.

    Out.

Re: Not pure perl
by BigRed (Acolyte) on Apr 30, 2001 at 21:53 UTC
    If it's okay to use telnet protocol instead of rsh, you can try Net::Telnet. I've used it to good effect before.
Re: Not pure perl
by isotope (Deacon) on Apr 30, 2001 at 21:51 UTC
    I'm looking through modules, but for now, at least for the kernel version, you might save some work using uname -r

    Update 1: You might look into Unix::Processors. Of course, if you start doing this you'll have to copy scripts around, or pipe them to the remote Perl...

    --isotope
    http://www.skylab.org/~isotope/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://76675]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found