I am trying to install IO::Socket::Timeout (as part of a requirement for Redis, on 5.14, on Linux as root).
I have tried in both CPAN and CPANM, when I enter the command
cpan IO::Socket::Timeout
It comes up with the error
t/timeout.t ............... ops Address already in use at /root/.cpan/build/IO-Socket-Timeout-0.32-ZVMh0b/t/tlib/TestTimeout.pm line 31.
cannot open port: 50420 at /opt/perl/lib/site_perl/5.14.2/Test/TCP.pm line 51.
# Child (test with no delays and no timeouts) exited without calling finalize()
t/timeout.t ............... 1/?
# Failed test 'test with no delays and no timeouts'
If I do
netstat -lntu | grep 50420
netstat -ntp | grep 50420
It doesn't show any port in use.
If I look at the timeout.t test that seems to be calling, it's
my $socket = IO::Socket::INET->new(
Listen => 5,
Reuse => 1,
Blocking => 1,
LocalPort => $port
) or die "ops $!";
If I download the gzip from cpan and try to install with
Perl Makefile.PL && make && make test
and I add some debug to display which port its trying, it tries different ports, eg
50341 or 50809 etc which aren't in use either
Any ideas what the problem may be, or how I can isolate ?
For whatever reason, it simply worked this morning. I can only think there was something else going on affecting a ports ability to be in use, but I'm not sure why this would be. The server was quite busy which could be related.
If anyone has any ideas on how to confirm why a port may come up as in use or unavailable (is there a timeout/sleep time for ports?), even though it doesn't appear in a netstat dump, I will gladly accept their answer.
Related
I am trying to connect to an Outlook email server via IMAP and the error I am getting is curious. Here is a sample of my code:
use Mail::IMAPClient;
my $imap = Mail::IMAPClient->new;
$host='outlook.office365.com';
$username='.....';
$password='.....';
$folder='INBOX';
$imap=Mail::IMAPClient->new(
Server => $host,
User => $username,
Password => $password,
Port => 993,
Ssl => 1,
Clear=> 5,
Folder => $folder,
Uid => 0,
) or die "Cannot connect to $host as $username: $#";
When I run this, the output line looks like this:
Cannot connect to outlook.office365.com as [...]: Socket closed while reading data from server.
More specifically, Socket closed while reading data from server is what is confusing me.
I specify port 993, so is the only remaining possible issue that there's a firewall in place that is preventing this? I have emailed my school's (this is a school email account) tech department (quite some time ago) and they have yet to get back, but hopefully I will hear from them soon.
I get an even stranger error when I remove the line specifying the port, I am including it only in the hopes it is somehow relevant or helpful:
Cannot connect to outlook.office365.com as [...]: Error sending '1 Login "baldassaren#wit.edu" {15}
[password is shown here, along with a newline character I can't seem to force here]
' to IMAP: Bad file descriptor at ./test.pl line 10.
Please check directly with openssl:
openssl s_client -connect outlook.office365.com:993
This should give you a connection and at the end the welcome message from the IMAP server:
* OK The Microsoft Exchange IMAP4 service is ready. ....
If this does not work the connection is blocked by firewall or so. If this works try connecting with IO::Socket::SSL, which is the module Mail::IMAPClient uses for SSL connections:
perl -MIO::Socket::SSL -e 'print IO::Socket::SSL->new(q[outlook.office365.com:993])->getline.""'
This should also give you the welcome message. If it does not there might be problems with certificate checking or so. In this case please post the versions of modules you use and the OS, e.g.
perl -e 'print "version=$^V, os=$^O\n"'
perl -MIO::Socket::SSL -e 'print IO::Socket::SSL->VERSION,"\n"'
perl -MMail::IMAPCient -e 'print Mail::IMAPClient->VERSION,"\n"'
But, if IO::Socket::SSL gets a successful connection please add the Debug => 1 option to Mail::IMAPClient->new and add the output to your question.
I'm working on a perl script using net::ssh2 to make a SSH connection to a remote server.
(I'm working on windows)
I chose Net::SSH2 because i had to make some SFTP connections in the same script.
For now, my sftp connections work perfectly. The problem is when i try to execute a "long-duration" command. I mean a command which execution can take more than 30sec.
$ssh2 = Net::SSH2->new();
$ssh2->connect('HOST') or die;
if($ssh2->auth(username=>'USER', password=>'PSWD'))
{
$sftp = Net::SFTP::Foreign->new(ssh2=>$ssh2, backend=>'Net_SSH2');
$sftp->put('local_path', 'remote_path');
$channel=$ssh2->channel();
##
$channel->shell('BCP_COMMAND_OR_OTHER_PERL_SCRIPT');
# OR (I tried both, both failed :( )
$channel->exec('BCP_COMMAND_OR_OTHER_PERL_SCRIPT');
##
$channel->wait_closed();
$channel->close();
print "End of command";
$sftp_disconnect();
}
$ssh2->disconnect();
When i execute this script, the connection is successfull, the file is correctly sent but the execution is not (completely) performed. I mean, I think the command is sent for execution but terminated immediatly or not sent at all, i'm not sure.
What i want is the script waits until the command is completly finished before disconnect everything (just because sometimes, i need to get the result of the command execution)
Does anyone know how to solve this? :( The cpan documentation is not very explicit for this
Thanks!
PS: I'm open to any remarks or suggestion :)
Edit: After some test, i can say that the command is sent but is interrupted. My test was to start another perl script on the remote server. This script writes in a flat file. In this test, the script is started, the file is half-filled. I mean, the file is brutaly stopped in the middle.
In the other hand, when i performed a "sleep(10)" just after the "$channel->exec()", the script goes to the end successfully.
Problem is, that I can't write a "sleep(10)" (i don't know if it will take 9 or 11 seconds (or more, you see my point)
You can try using Net::SSH::Any instead.
It provides a higher level and easier to use API and can use Net::SSH2 or Net::OpenSSH to handle the SSH connection.
For instance:
use Net::SSH::Any;
my $ssh = Net::SSH::Any->new($host, user => $user, password => $password);
$ssh->error and die $ssh->error;
my $sftp = $ssh->sftp;
$sftp->put('local_path', 'remote_path');
my $output = $ssh->capture($cmd);
print "command $cmd output:\n$output\n\n";
$sftp->put('local_path1', 'remote_path1');
# no need to explicitly disconnect, connections will be closed when
# both $sftp and $ssh go out of scope.
Note that SFTP support (via Net::SFTP::Foreign) has been added on version 0.03 that I have just uploaded to CPAN.
This problem is really puzzling to me: I have the following script working on vmware server 2.0:
#!/usr/local/bin/perl
# server (transmitter)
use strict;
use IO::Socket::Multicast6;
use IO::Interface;
use constant GROUP => "235.1.1.2";
use constant PORT => "3000";
my $sock = IO::Socket::Multicast6->new(
Proto=>"udp",
Domain=>AF_INET,
PeerAddr=>GROUP,
PeerPort=>PORT);
$sock->mcast_if("eth1");
$sock->mcast_ttl(10);
while (1) {
my $message = localtime();
$sock->send($message) || die "Could not send: $!";
} continue {
sleep 4;
}
It works great on vmware server. I have cloned this VM to an EXSi server but running the same exact copy of the virtual machine running the script, and I get the following error:
Can't call method "mcast_if" on an undefined value
Im really puzzled by this as I am not sure what the problem could be.
there is really nothing different except for the CPU running on both machines, but I don't see how something so low level can be causing an issue but I could be wrong. perl -d wasn't very helpful.
Thanks.
It's failing to create the socket, use some error checking to try to find out why. Eg:
my $sock = IO::Socket::Multicast6->new(
Proto=>"udp",
Domain=>AF_INET,
PeerAddr=>GROUP,
PeerPort=>PORT)
or die "Socket failed: $!";
The new() constructor is failing, but not raising an exception. I don’t know its API: is there some way to get it to tell you why?
Otherwise you might try errno (that is, $!).
I'm using Padre as my IDE with Strawberry Perl on Windows 7 Pro.
I'm trying to create a perl script that goes to a text file on a website, and then reads/copies the text file.
But I can't get LWP to work even for the simplest LWP command ever.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
getprint('http://www.perlmeme.org') or die 'Unable to get page';
exit 0;
I keep getting this error message:
500 can't connect to proxy.sn.no:8001 (Bad hostname)
eg 500 can't connect to (Bad hostname) http://www.perlmeme.org
I've been googling around, used Microsoft Fixit to reset ports, etc but I still can't make it work. http//www.justskins.com/forums/lwp-connect-failing-bad-119421.html
Can anyone help me out here? Been stuck for many hours :(
Edit:
--1 foreach my $key (keys %ENV) { print "$key: $ENV{$key}\n" if $key =~ m/proxy/i; }
Yes it prints out FTP_PROXY and HTTP_PROXY both followed by this: http://proxy.sn.no:8001/
That's the proxy that I got from this helpthread How do I install a module? Strawberry Perl issues
I had the proxy problem, then I tried the config from that thread, then the proxy problem was still there.
--2 I'm not expecting any proxy to be used on my end or anything. Just wanna connect the perl script to the website to retrieve a text document.
--3 ping had 0% loss. (I can only post two hyperlinks in this post)
--4 I'm using Windows.
LWP will honor the http_proxy environment variable and try to use it as an HTTP proxy. Check with env | grep http_proxy on Unix.
Has anyone got Sys::Syslog to work on Solaris? (I'm running Sys::Syslog 0.05 on Perl v5.8.4 on SunOS 5.10 on SPARC). Here's what doesn't work for me:
openlog "myprog", "pid", "user" or die;
syslog "crit", "%s", "Test from $0" or die;
closelog() or warn "Can't close: $!";
system "tail /var/adm/messages";
Whatever I do, the closelog returns an error and nothing ever gets logged anywhere.
By default, Sys::Syslog is going to try to connect with one of the following socket types:
[ 'tcp', 'udp', 'unix', 'stream' ]
On Solaris, though, you'll need to use an inet socket. Call:
setlogsock('inet', $hostname);
and things should start working.
In general you can answer "does module $x work on platform $y" questions by looking at the CPAN testers matrix, like here.
setlogsock('inet') didn't do it for me (it looks for host "syslog") but building and installing Sys::Syslog from CPAN did. The Sys::Syslog that comes with Solaris 10 is ancient.