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.
Related
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.
I am looking for ways to get file checksums in Perl but not by executing the system command cksum -- would like to do it in Perl itself because the script needs to be portable between UNIX and Windows. cksum <FILENAME> | awk '{ print $1 }' works on UNIX but obviously not in Windows. I have explored MD5 but it seems like getting a file handle is necessary and generally it doesn't seem like a very compact way to get that data (one-liner preferable).
Is there a better way?
Here are three different ways depending on which modules you have available:
use Digest::MD5 qw(md5_hex);
use File::Slurp;
print md5_hex(read_file("filename")), "\n";
use IO::All;
print md5_hex(io("filename")->all), "\n";
use IO::File;
print md5_hex(do { local $/; IO::File->new("filename")->getline }), "\n";
Not completely one-line but pretty close.
Replace Digest::MD5 with any hash algorithm you want, e.g. SHA1.
IO::File is in core and should be available everywhere, but that's the solution I personally dislike the most. Anyway, it works.
I couldn't make any of the above work for me in windows, I would always get an incorrect MD5. I got suspicious that it was being caused by differences in linebreak, but converting the file to DOS or to unix made no difference. The same code with the same file would give me the right answer on linux and the wrong one in windows. Reading the documentation, I finally found something that would work both in windows and linux:
use Digest::MD5;
open ($fh, '<myfile.txt');
binmode ($fh);
print Digest::MD5->new->addfile($fh)->hexdigest;
I hope this helps other people having difficulty in windows, I find it so weird that I didn't find any mentions to problems on windows...
This also works:
use Digest::MD5 qw(md5_base64);
...
open(HANDLE, "<", $dirItemPath);
my $cksum = md5_base64(<HANDLE>);
print "\nFile checksum = ".$cksum;
I am looking for ways to get file checksums in Perl but not by executing the system command cksum -- would like to do it in Perl itself because the script needs to be portable between UNIX and Windows. cksum <FILENAME> | awk '{ print $1 }' works on UNIX but obviously not in Windows. I have explored MD5 but it seems like getting a file handle is necessary and generally it doesn't seem like a very compact way to get that data (one-liner preferable).
Is there a better way?
Here are three different ways depending on which modules you have available:
use Digest::MD5 qw(md5_hex);
use File::Slurp;
print md5_hex(read_file("filename")), "\n";
use IO::All;
print md5_hex(io("filename")->all), "\n";
use IO::File;
print md5_hex(do { local $/; IO::File->new("filename")->getline }), "\n";
Not completely one-line but pretty close.
Replace Digest::MD5 with any hash algorithm you want, e.g. SHA1.
IO::File is in core and should be available everywhere, but that's the solution I personally dislike the most. Anyway, it works.
I couldn't make any of the above work for me in windows, I would always get an incorrect MD5. I got suspicious that it was being caused by differences in linebreak, but converting the file to DOS or to unix made no difference. The same code with the same file would give me the right answer on linux and the wrong one in windows. Reading the documentation, I finally found something that would work both in windows and linux:
use Digest::MD5;
open ($fh, '<myfile.txt');
binmode ($fh);
print Digest::MD5->new->addfile($fh)->hexdigest;
I hope this helps other people having difficulty in windows, I find it so weird that I didn't find any mentions to problems on windows...
This also works:
use Digest::MD5 qw(md5_base64);
...
open(HANDLE, "<", $dirItemPath);
my $cksum = md5_base64(<HANDLE>);
print "\nFile checksum = ".$cksum;
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.
I have a Perl program, intended to be run from a subversion post-commit script, which needs to connect to a HTTPS based Web API.
When I test the program from an interactive shell, as root, it works just fine.
When it runs from the post-commit script, it errors out, and the response from LWP is along the lines of "500 Connect failed".
There's some evidence that when run from the post-commit script, SS isn't enabled, because when I set $ENV{HTTPS_DEBUG} =1; and run it as root, I see debug output, such as
SSL_connect:before/connect initialization
but from the post-commit script, non of the SLL debug info is printed.
The the post-commit script runs as user apache.
I'm running CentOS 64bit.
It's been years since I've done any Unix work, so I'm not sure what the next steps are to get SSL working in this case.
The difference in environments makes me suspicious. Like running cron jobs, it may be that the environment, the INC path, or the perl interpreter itself is sufficiently different that it can't find Crypt::SSLeay or whatever else you're using for SSL support.
As a troubleshooting step, try using this program in both your shell and in the post-commit hook to see if there is an environment difference between the two. This will dump several runtime variables that show what perl knows about its environment to a tempfile.
#!/usr/bin/perl
use Data::Dumper;
use File::Temp qw( tempfile );
use strict;
use warnings;
my $tempdir = '/tmp'; # Change this if necessary.
my( $fh, $fname ) = tempfile( "tempXXXXXX", DIR => $tempdir, UNLINK => 0 );
print $fh Data::Dumper->Dump( [ \#INC, \%INC, $^X, $0, $], \#ARGV, \%ENV ],
[ qw( #INC %INC ^X 0 ] #ARGV %ENV ] ) ] );
close( $fh );
# Change this if the post-commit hook doesn't pass stdout back to you.
print "Wrote data to $fname.\n";
__END__
If they differ substantially, your next step would be to make the environment in the post-commit hook the same as under your shell, e.g. adding a use lib qw( /path/to/where/ssl/modules/are/installed ); line to your script's use section, by setting PERL5LIB, using the full path to a different Perl interpreter, or whatever is appropriate. See perldoc perlvar for a description of some of the variables, if you're not familiar with them.
It's not a Perl issue. Perl is doing only what it is told. Figure out what is saying "http:" vs "https:" above Perl, and sort that out. You don't need to "configure Perl... to use SSL".
I had to run this:
setsebool httpd_can_network_connect=on
to allow the httpd process to make network connections