- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: wrong result when executing syscall from a PER...
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
Forums
Discussions
Discussions
Discussions
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
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
04-26-2004 04:14 AM
04-26-2004 04:14 AM
I've written a very simple PERL program.
The PERL program executes a system call, namely "ping host_j -n 1" to check if the host_j is reachable;
even if the host_j is reachable the system call returns error -1 ... this happens either by system(ping) or by 'ping' ...
I check the result by testing $?
thanks
Enrico
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:24 AM
04-26-2004 04:24 AM
Solution`ping host_j -n i`;
if(($? >> 8) == 1){ # Exit status of command run by back ticks
print "Oh dear I punged with no result\";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:26 AM
04-26-2004 04:26 AM
Re: wrong result when executing syscall from a PERL program
-1 might also be 255
# man perlvar
--8<---
$CHILD_ERROR
$? The status returned by the last pipe close, back�
tick (``) command, successful call to wait() or
waitpid(), or from the system() operator. This is
just the 16-bit status word returned by the wait()
system call (or else is made up to look like it).
Thus, the exit value of the subprocess is really
("$? >> 8"), and "$? & 127" gives which signal, if
any, the process died from, and "$? & 128" reports
whether there was a core dump. (Mnemonic: similar
to sh and ksh.)
Additionally, if the "h_errno" variable is sup�
ported in C, its value is returned via $? if any
"gethost*()" function fails.
If you have installed a signal handler for
"SIGCHLD", the value of $? will usually be wrong
outside that handler.
Inside an "END" subroutine $? contains the value
that is going to be given to "exit()". You can
modify $? in an "END" subroutine to change the
exit status of your program. For example:
END {
$? = 1 if $? == 255; # die would make it 255
}
Under VMS, the pragma "use vmsish 'status'" makes
$? reflect the actual VMS exit status, instead of
the default emulation of POSIX status; see "$?" in
perlvms for details.
-->8---
Attached is a small script that shows fine use of ping to scan the LAN for on-line machines in the segment of the host that's calling it
Enjoy, Have FUN! H.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:30 AM
04-26-2004 04:30 AM
Re: wrong result when executing syscall from a PERL program
my $rslt = system("ping host_j - n 1");
print "Result = ",$rslt,"\n";
should be required but this is a less-than-reliable method. Abount the only thing that you will know is whether or not the hostname can be resolved; this really tells you nothing about actually reaching the remote host because for almost all cases, ping will return 0.
I would use the Net::Ping module so that you can get much more meaning results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:30 AM
04-26-2004 04:30 AM
Re: wrong result when executing syscall from a PERL program
my $rslt = system("ping host_j - n 1");
print "Result = ",$rslt,"\n";
should be required but this is a less-than-reliable method. About the only thing that you will know is whether or not the hostname can be resolved; this really tells you nothing about actually reaching the remote host because for almost all cases, ping will return 0.
I would use the Net::Ping module so that you can get much more meaning results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:41 AM
04-26-2004 04:41 AM
Re: wrong result when executing syscall from a PERL program
One thing to note using Net::Ping is that if you use the typicalICMP protocol (the same as the ping command) as a non-root user, the call will fail. Only super-user is allowed to use ICMP. For this reason, the ping program is a setuid program. Ordinary users can use the tcp or udp protocols.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2004 04:42 AM
04-26-2004 04:42 AM
Re: wrong result when executing syscall from a PERL program
No points please.