I have a script for pinging the switches and giving me the report:-
#!/usr/local/bin/perl
#!/bin/ksh
#!/usr/bin
#etc
`source /export/home/chinnigd/.profile`;
@names = `cat switches|cut -f1 -d' '`;
@ip = `cat switches|cut -f2 -d' '`;
$num = @names;
$re ="Empty";
$i = 0;
$flag = 0;
while ($i lt $num)
{
$ou = `ping $ip[$i]`;
if ( $ou == "no answer from $ip[$i]" )
{
print "ALERT!!The Switch is DOWN-->$names[$i]\n";
$flag = 1;
}
else
{
print "The Switch is up-->$names[$i]\n";
}
$i = $i + 1;
}
if ($flag -eq 0)
{
print "\n";
print "All the switches,totally $num Switches,in the network are UP\n";
print "\n";
}
This script works fine in the command line but when I put it in the crontab, the cron job run at the specified time but the script doesn't work properly i.e. some commands in the script doesn't execute correctly and I always get the output as " All the switches. totally <> switches in the network are UP".
kindly help me how to solve this