PDA

View Full Version : Small Perl Script for you Linux Folders


{PMS}fishy
07-19-08, 04:32 PM
Here is a simple Perl script for anyone folding on multiple linux machines. I have passed my SSH key around to all the machines so that I don't have to code the password into this script. Its pretty simple, but it sure beats login into each box to check the machine.

You will need to adjust the IPs & either add password or pass around your key.


#!/usr/bin/perl
use Net::SSH qw(sshopen2);
use strict;

my @machines = (148 .. 163);

foreach (@machines) {
my $host = "192.168.1." . "$_";
print "On Host: $host \n\n";
sshopen2($host, *READER, undef, "cat /folding/unitinfo.txt");
while (<READER>) {
chomp();
print "$_ \n";

}
close(READER);
}


A sample output is posted below.

Current Work Unit
-----------------
Name: Protein in POPC
Tag: P2605R17C70G74
Download time: July 18 23:40:18
Due time: July 22 23:40:18
Progress: 81% [||||||||__]
On Host: x.x.x.162

Current Work Unit
-----------------
Name: Protein in POPC
Tag: P2605R16C420G74
Download time: July 18 16:39:45
Due time: July 22 16:39:45
Progress: 82% [||||||||__]
On Host: x.x.x.163

Current Work Unit
-----------------
Name: Protein in POPC
Tag: P2605R17C62G74
Download time: July 18 23:40:20
Due time: July 22 23:40:20
Progress: 82% [||||||||__]
On Host: x.x.x.164

{PMS}fishy
07-23-08, 06:53 PM
Not helpful for anyone? No one has more than 1 Linux machine?

ihrsetrdr
07-23-08, 09:59 PM
To be honest I'm not very familiar with editing Perl scripts, but I did try it out. I currently have only one folding box with Linux as the host o/s; the other folding machines have XP with 2 each Linux VMs. I inserted the IP of one VM into the script, but was unsure what to do with with "$_". Also, with is "$host \n\n" ? It failed with a bunch of syntax errors, so I know I didn't edit the script correctly.

If you could provide some pointers, I'd like to try it again.

gsrcrxsi
07-23-08, 10:42 PM
wouldnt it just be easier to use fahmon?

{PMS}fishy
07-24-08, 08:22 AM
To be honest I'm not very familiar with editing Perl scripts, but I did try it out. I currently have only one folding box with Linux as the host o/s; the other folding machines have XP with 2 each Linux VMs. I inserted the IP of one VM into the script, but was unsure what to do with with "$_". Also, with is "$host \n\n" ? It failed with a bunch of syntax errors, so I know I didn't edit the script correctly.

If you could provide some pointers, I'd like to try it again.

You do not need to change anything other than the range for @machines. In my case, my machine IPs are 148 thru 163. If you look a few lines later, ( my $host = "192.168.1." . "$_"; ) you can see that I am concatenating IPs together instead of having to type them all out. If you only have one machine, it isn't really going to buy you anything. Its when you have lots that it starts to help.

wouldnt it just be easier to use fahmon?

Well, I have 16 Linux machines, so, not for me.

gsrcrxsi
07-24-08, 09:22 AM
as long as they are all networked, fahmon can monitor them all with 1 window.

mbentley
07-24-08, 09:44 AM
as long as they are all networked, fahmon can monitor them all with 1 window.

but wouldn't you need a network shared on each of the linux boxes for fahmon to work? i did something very similar to check on remote linux boxes to pull their unitinfo.txt file using ssh. simple but effective if you want to just make sure they are alive :)

gsrcrxsi
07-24-08, 10:10 AM
all i did was edit my /etc/fstab (may have to edit exports file as well) to mount the folding directory to a local directory. pointed fahmon to the local directory and viola, it works!

ihrsetrdr
07-26-08, 03:20 AM
You do not need to change anything other than the range for @machines. In my case, my machine IPs are 148 thru 163. If you look a few lines later, ( my $host = "192.168.1." . "$_"; ) you can see that I am concatenating IPs together instead of having to type them all out. If you only have one machine, it isn't really going to buy you anything. Its when you have lots that it starts to help..


I changed the IP range to conform to my home net, and got the following output:

hrsetrdr@debian-DS3-1:~$ #!/usr/bin/perl
hrsetrdr@debian-DS3-1:~$ use Net::SSH qw(sshopen2);
bash: syntax error near unexpected token `('
hrsetrdr@debian-DS3-1:~$ use strict;
bash: use: command not found
hrsetrdr@debian-DS3-1:~$
hrsetrdr@debian-DS3-1:~$ my @machines = (100 .. 150);
bash: syntax error near unexpected token `('
hrsetrdr@debian-DS3-1:~$
hrsetrdr@debian-DS3-1:~$ foreach (@machines) {
bash: syntax error near unexpected token `@machines'
hrsetrdr@debian-DS3-1:~$ my $host = "192.168.1." . "$_";
bash: my: command not found
hrsetrdr@debian-DS3-1:~$ print "On Host: $host \n\n";
Warning: unknown mime-type for "On Host: \n\n" -- using "application/*"
Error: no such file "On Host: \n\n"
hrsetrdr@debian-DS3-1:~$ sshopen2($host, *READER, undef, "cat /folding/unitinfo.txt");
bash: syntax error near unexpected token `$host,'
hrsetrdr@debian-DS3-1:~$ while (<READER>) {
bash: syntax error near unexpected token `)'
hrsetrdr@debian-DS3-1:~$
Display all 1434 possibilities? (y or n)
hrsetrdr@debian-DS3-1:~$ t "$_ \n";
bash: t: command not found
hrsetrdr@debian-DS3-1:~$
hrsetrdr@debian-DS3-1:~$ }
bash: syntax error near unexpected token `}'
hrsetrdr@debian-DS3-1:~$ close(READER);
bash: syntax error near unexpected token `READER'
hrsetrdr@debian-DS3-1:~$ }
bash: syntax error near unexpected token `}'
hrsetrdr@debian-DS3-1:~$


Maybe you can spot something that I borked in this...

{PMS}fishy
07-26-08, 10:54 AM
Net::SSH needs to be installed.

http://search.cpan.org/dist/Net-SSH-Perl/

ihrsetrdr
07-27-08, 03:39 AM
I booted one of my Windows vm hosting rigs back into Linux, and see that each Linux machine already has ssh installed. I can connect via ssh by just typingssh 192.168.1.xxx

and can then browse the directories, etc.

I searched available modules through synaptic & added libnet-stfp-ruby1.8 and libnet-ssh-ruby1.8 since they seemed associated with net::ssh.

All the folding rigs here are on KVM switches, so none are out there 'headless', but this is interesting none-the-less. ;)

{PMS}fishy
07-27-08, 01:04 PM
I booted one of my Windows vm hosting rigs back into Linux, and see that each Linux machine already has ssh installed. I can connect via ssh by just typingssh 192.168.1.xxx

and can then browse the directories, etc.

I searched available modules through synaptic & added libnet-stfp-ruby1.8 and libnet-ssh-ruby1.8 since they seemed associated with net::ssh.

All the folding rigs here are on KVM switches, so none are out there 'headless', but this is interesting none-the-less. ;)

I know you can just SSH to each machine, but that gets old when you have 15+ Linux machines. If I were a little less lazy, I'd have this make me a web page too, so all I need to do is go to a link.

The link I gave you is for the PERL ssh module, the ruby ones are not going to help you at all.

ihrsetrdr
07-27-08, 04:05 PM
I haven't taken the time to read up the link, but I am off work tomorrow so I'll spend some quality time there.