Question Locked

The simple ping command

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi all,

Got a situation that seems funny to me. I wrote a simple perl script
that performs a ping command to a certain address (This is on a
IMAC).

See below

# Varible definitions
$monivest_ipaddress = "192.168.32.111";
$monivest_ipresults = "monivestip.txt";
#
#-----------------------------------------------------
system "ping -c 15 $monivest_ipaddress > $monivest_ipresults";
END;

***************************

When I use the full path to run the script it works fine. When I use the
./ and the file name it works fine. Now when I put it in cron I get the
following message.

sh: ping: command not found

Can someone tell me what is going on and how I may fix it.

Thanks
Bill

5 replies

by synner

I would venture to guess that you are forking a new shell and that new shell didn't source the profile and you don't have any paths in your environment. For that reason, the full path of the system command is always included in scripts that I see.

Just a guess, not a *nix person.

by deity_chooch

I think when you execute the Perl script from the shell you have those environment variables set and that allows the Perl script to find the ping command in the correct path. I am a Linux person, but can't say I've run into this issue (maybe because I make bash scripts instead of using Perl). Anyway, I think you've got it right and that using the absolute path in the Perl script will fix this.

by billsommerville

Your commends were very helpful. Please see my comment
to SYNner.

Thanks Again.

by billsommerville

It all seemed to be a permissions problem. I did not know
how to fix the cron profile to have the access to the sbin
folder. I kind of thought there may be a security issue there
that I will need more research later. So the quick way to get
it to work was to copy the ping command to the bin folder.
After that everything else was fine. Thanks for the
direction***.

This discussion is closed to new replies.