title: How can I ping a host with a Perl one-liner with Net::Ping?
body: <p>Trying to integrate the following Perl one-liner into a shell script. This code works within a Perl script but not as a one-liner executed from a shell script.</p>
  
  <p>I've tried replacing <code>$host</code> with a real hostname with no luck.</p>
  
  <pre><code>#!/bin/ksh
  
  hosts="host1 host2 host3"
  
  PERL=/usr/bin/perl
  
  # Check to see if hosts are accessible.
  for host in $hosts
  do
     #echo $host
     $PERL -e 'use Net::Ping; $timeout=5; $p=Net::Ping-&gt;new("icmp", $timeout) or die bye ; print "$host is alive \n" if $p-&gt;ping($host); $p-&gt;close;'
  done
  </code></pre>