Home: Perl Programming Help: Intermediate:
Plink command hangs in perl?

New User

Mar 2, 2011, 11:01 AM

Views: 4682
Plink command hangs in perl?

I have this problem across several Perl scripts. I have to use plink to ssh into a device. I am running Active Perl 5.10.0 Build 1004 on Windows Server 2003 with Putty release .056.

If I run the command this way:
$svctask = "plink.exe -ssh -l $user -i $svckey -2 $IP svcinfo lshost -delim :";
@shstlist = qx ($svctask) or die "Unable to open SVC\n";
print "Enter a \n";
print "\t1) WWPN\n";
print "\t2) Server name\n";
print "\n\t ?";
chomp($choice = <>);
$choice = uc($choice);
}until($choice =~ m/[0-9]{1}/);
The script hangs and I can not make a choice. I have to CTRL C out which does me no good. If I move the plink command below the until statement, I am able to make a choice and the script continues until I have another pause for answer section and again it hangs. Is there a perl command that exits out of plink? I have used this same bit of code in other scripts that don't require SSH and it works just fine.

Veteran / Moderator

Mar 2, 2011, 12:48 PM

Views: 4677
Re: [bornwildnfree] Plink command hangs in perl?

Is there a reason you can't use one of Perl's ssh modules?

New User

Mar 2, 2011, 12:49 PM

Views: 4675
Re: [FishMonger] Plink command hangs in perl?

That's looking like what I'm going to have to do although perl's SSH modules on Windows have been difficult to configure.

Veteran / Moderator

Mar 2, 2011, 1:17 PM

Views: 4674
Re: [bornwildnfree] Plink command hangs in perl?

Net::SSH is easiy to install

C:\Users\RKB>ppm install Net::SSH
Downloading Net-SSH-0.09...done
Unpacking Net-SSH-0.09...done
Generating HTML for Net-SSH-0.09...done
Updating files in site area...done
2 files installed

New User

Mar 15, 2011, 1:57 PM

Views: 4643
Re: [bornwildnfree] Plink command hangs in perl?

cpan - Net::SSH does not play well with the device I'm trying to SSH into because we have to use keys. We actually solved this by having the perl script write the command to a .cmd file and running it that way.
open(MyFile,">","svc.cmd") or die "Unable to create file svc.cmd\n";
$svctask = "ECHO OFF\nplink.exe -batch -t -ssh -l $user -i $svckey -2 $IP svcinfo lshostvdiskmap -delim : $hostid";
print MyFile "$svctask";
close MyFile;
@svcvdisklist = qx ("svc.cmd") or die "Unable to open SVC\n";

Veteran / Moderator

Mar 15, 2011, 4:38 PM

Views: 4642
Re: [bornwildnfree] Plink command hangs in perl?

The list form of the system call should have worked as well without the extra steps of creating and executing a .cmd file.