- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script help needed
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2011 06:38 PM
тАО05-22-2011 06:38 PM
Perl script help needed
Could you guys help me to figure out how can I set a timeout value smaller that 1 sec ? I tried 0.3 but it didn't work. The program actually does stuff longer then if the value is set to 1.
#!/usr/bin/perl -w
use strict;
use warnings;
use Socket;
my $timeout = 1;
open (MYFILE, '/home/x/robot/ips.txt');
while (
chomp;
$a="$_";
socket SOCKET, PF_INET, SOCK_STREAM, getprotobyname('tcp') or die;
my $ip = inet_aton( $a );
my $address = sockaddr_in( 80, $ip );
eval {
local $SIG{ALRM} = sub { die "timeout" };
alarm($timeout);
connect (SOCKET, $address) || error();
alarm(0);
};
if ($@) {
close SOCKET || die "close: $!";
#print "$a is NOT listening on tcp port 80.\n";
}
else {
close SOCKET || die "close: $!";
open (OUTFILE, '/home/x/robot/ip80ok.txt');
print "$a\n";
print OUTFILE "$a\n";
close (OUTFILE);
}
}
close(MYFILE);
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-22-2011 09:41 PM
тАО05-22-2011 09:41 PM
Re: Perl script help needed
The description of "alarm" in perlfunc(1) man page says:
-----
[...]
For delays of finer granularity than one second, the Time::HiRes module (from CPAN, and starting from Perl 5.8 part of the standard distribution) provides ualarm(). You may also use Perl's four-argument version of select() leaving the first three arguments undefined, or you might be able to use the "syscall" interface to access setitimer(2) if your system supports it. See perlfaq8 for details.
[...]
-----
Information about Time::HiRes can of course be found at the cpan.org website:
http://search.cpan.org/~zefram/Time-HiRes-1.9722/HiRes.pm
MK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2011 05:10 AM
тАО05-23-2011 05:10 AM
Re: Perl script help needed
You don't need the '-w' switch on the shebang line *and* the 'warnings' pragma. Use the pragma.
The '-w' switch applies globally whereas the pragma allows much finer control over what you want to be warned about and where you might want to temporarily turn off warnings.
As Matti noted, use the 'Time::HiRes' module for working with times less than one-second. This module is part of the core Perl distribution so you can immediately deploy it.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2011 06:57 AM
тАО05-23-2011 06:57 AM
Re: Perl script help needed
I have no idea how to do this.
Some example based on the code above please ?
Regards
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-23-2011 07:02 AM
тАО05-23-2011 07:02 AM
Re: Perl script help needed
I have no idea how to do this.
Some example based on the code above please ?
Homework, eh?
Start by adding the 'Time::HiRes' module:
use Time::HiRes qw(ualarm);
Now, change 'alarm()' to 'ualarm()'
Remember, the 'ualarm' runs in *micro*seconds.
Regards!
...JRF...