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:
#!/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........
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?
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 ....."
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 -
$
$ 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.
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.