How to input the return value (1 or 0) ping cmd to a variable

Hi

I would like to ask about my plan script

I have this several workstation want to monitor and execute a command without logging it we use "rsh $host "<command>" i create csh script using foreach to loop my several workstation, my problem with the rsh command is if it encounter a workstation that is being down or move therefore no connection the rsh cmd stop or even not continue. here my initial script and my problem:

#!/usr/bin/csh -f

foreach host(host1 host2 host.....)
ping -t 30 $host 5 > /dev/null
set status = ( I want the return value of the ping to be the "status" variable )
    if( status == 0 ) then
        rsh $host " uname -a"
    else
        echo " ---$host unavailable---"
    endif

echo " ----- END -----"
sleep 1

end

Any suggestion would be greatly appreciated,
thanks in advance

set status = $?
if ( $status ......

By the way thanks for the reply i solve my problem by just not using a variable i guess csh automatically declare the return values of the previous command as status variable

#!/usr/bin/csh -f
foreach host(host1 host2 host.....)
ping -t 30 $host 5 >& /dev/null
    if( status == 0 ) then
        rsh $host " uname -a"
    else
        echo " ---$host unavailable---"
    endif

echo " ----- END -----"
sleep 1

end

I used redirection for the stdout and stderr so that no ping result command appears in my script

So it does! Who'd have thunk it?

I still think you need the $, though.

if( $status == 0 ) then
1 Like