Problem with perl openssh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with perl openssh
# 1  
Old 10-27-2010
Problem with perl openssh

hello, can anyone help me with this problem? im just a beginner and currently starting to program in perl, also i just installed openssh because what i really need is to ssh to a ubuntu server.
so I tried my code:
Code:
#!/usr/bin/perl

use strict;
use warnings;
use Net::OpenSHH;

my $ssh = Net::OpenSSH->new('IPAddress');
$ssh->error and die "ssh connection failed: ". $ssh->error;

my problem is that it keeps returning errors that I dont understand, it says:
use of uninitialized value $default_stdin_fh in anonymous hash....
almost the whole errors says like this but changes to $default_stdout_fh,$default_stderr_fh,$master_stdi n_fh........


what does these error mean?

Last edited by Yogesh Sawant; 10-27-2010 at 04:20 AM.. Reason: added code tags
# 2  
Old 10-27-2010
Can you try something like this? Source: Net::OpenSSH

Quote:
mod_perl and mod_perl2

mod_perl and mod_perl2 tie STDIN and STDOUT to objects that are not backed up by real file descriptors at the operative system level. Net::OpenSSH will fail if any of these handles is used explicetly or implicitly when calling some remote command.
The workaround is to redirect them to /dev/null or to some file:
open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
my $ssh = Net::OpenSSH->new($host,
default_stdin_fh => $def_in);


my $out = $ssh->capture($cmd1);
$ssh->system({stdout_discard => 1}, $cmd2);
$ssh->system({stdout_to_file => '/tmp/output'}, $cmd3);

Also, note that from a security stand point, running ssh from inside the webserver process is not a great idea. An attacker exploiting some Apache bug would be able to access the ssh keys and passwords and gain unlimited access to the remote systems.
If you can, use a queue (as TheSchwartz) or any other mechanism to execute the ssh commands from another process running under a different user account.
At a minimum, ensure that ~www-data/.ssh (or similar) is not accessible through the web server!
# 3  
Old 10-27-2010
hello sir, thanks, but im only starting so the concern right now is to be able to connect.
so what you mean is to add these lines to my code?


Code:
open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
my $ssh = Net::OpenSSH->new($host,
default_stdin_fh => $def_in);

my $out = $ssh->capture($cmd1);
$ssh->system({stdout_discard => 1}, $cmd2);
$ssh->system({stdout_to_file => '/tmp/output'}, $cmd3);


I already add them to the code but it gives me errors of"global symbol "$cmd1" requires explicit package name ....."

sorry really having hard time understanding yet

Last edited by pludi; 10-27-2010 at 04:21 AM.. Reason: added code tags
# 4  
Old 10-27-2010
oh no! My point was not to copy the code which I quoted. That was just an example.

I was about to say that - may be something like default_stdin_fh => $def_in needs to be set in your code next to your IP address?
# 5  
Old 10-27-2010
Quote:
Originally Posted by samohung390
...
my problem is that it keeps returning errors that I dont understand, it says:
use of uninitialized value $default_stdin_fh in anonymous hash....
almost the whole errors says like this but changes to $default_stdout_fh,$default_stderr_fh,$master_stdi n_fh........

what does these error mean?
It means exactly what it says.
$default_stdin_fh has not been initialized, and therefore perl shows that warning.

A very short example might help in understanding this better -

Code:
$
$ perl -wle 'my $x; if ($x eq "hello") {print "HELLO"}'
Use of uninitialized value $x in string eq at -e line 1.
$
$

I declared the scalar $x, but did not initialize it. Perl doesn't know how to compare a literal string "hello" with an uninitialized value of $x. So it shows the warning.

Note that it's a warning, not an error. If I remove the "-w" flag, then this will not be shown.

Code:
$
$ perl -le 'my $x; if ($x eq "hello") {print "HELLO"}'
$

That's the same as removing the "use warnings" statement from a Perl program file - although it's highly recommended to retain it.

Of course, the problem isn't fixed by turning warnings off. You'll have to actually initialize the scalar/array/hash/whatever to make your program work.

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Openssh 6.8

Hi im using redhat enterprise linux 7 im trying to update to the latest openssh version 6.8 i ran the command yum update openssh and this upgraded only to version 6.6 how can i update to the latest version 6.8? thanks! (5 Replies)
Discussion started by: guy3145
5 Replies

2. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

3. UNIX for Advanced & Expert Users

Problem with OpenSSH Remote Port Forwarding with Bind_address

As in the ssh(1) man page: -R bind_address:]port:host:hostport .......By default, the listening socket on the server will be bound to the loopback interface only. This may be overridden by specifying a bind_address. An empty bind_address, or the address `*', indicates... (2 Replies)
Discussion started by: ahmad.zuhd
2 Replies

4. Fedora

OpenSSH Problem

Hello, I cannot seem to loggon to a machine using ssh/scp. Whenevr I do it closes the connection (error message : lost connection)but it appears to be the host machine closing rather than the destination which puzzles me even more. What is even weirder is that as a root user it works but as a... (1 Reply)
Discussion started by: mojoman
1 Replies

5. AIX

AIX 6.1 - openssh - problem

Hello, I am new in aix unix. First i install openssl - success, next step i try install openssh when i put command geninstall -Y -d /myssh openssh.base i have this message: What is the problem? Thanks for help. Sorry for my bad english i still learning. ---------- Post updated at... (2 Replies)
Discussion started by: bieszczaders
2 Replies

6. UNIX Desktop Questions & Answers

OpenSSH

Hello, I downloaded Cygwin to practice on my coursework from home. I was told to download the OpenSSH from Cygwin website so that I can access my files from home. However, the file saves itself with a cgi extension and I have no idea as to what I am supposed to do next. I found info on some... (1 Reply)
Discussion started by: feliks0
1 Replies

7. UNIX for Dummies Questions & Answers

A problem about openssh

When I first link a computer with ssh , the information "Warning: Permanently added ... (RSA) to the list of known hosts." will be occured. How can i avoid this information without use the parameter '-q'? tks!!! (2 Replies)
Discussion started by: ragehunter
2 Replies

8. Shell Programming and Scripting

problem with perl

hi, i have a script that coverts the file time in epoch time.but the problem is perl is not working inside the k-shell ---------------------------------------------------------------- #!/bin/ksh echo "Enter the file" read n perl -e 'print ((stat("n")))'... (6 Replies)
Discussion started by: ali560045
6 Replies

9. UNIX for Dummies Questions & Answers

OpenSSH

Help! SSH is returning the following error message: OpenSSL version mismatch. Built against 90581f, you have 90602f How can I correct this? (21 Replies)
Discussion started by: chenly
21 Replies

10. UNIX for Dummies Questions & Answers

Problem installing openssh v2.9-p2

I am trying to install openssh v2.9-p2 on Solaris 8. I already installed zlib and openssl, as required in INSTALL file. But when I issue ./configure to configure openssh v2.9-p2 for my platform ( I got the sources), it stops in the folowing message: checking for OpenSSL directory... configure:... (1 Reply)
Discussion started by: htsubamoto
1 Replies
Login or Register to Ask a Question