/* */

parse arg host

tmpnam='t:checkhost-'time(s)
address command 'ping -c3 -q 'host' > 'tmpnam
if RC = 1 then
do
    delete(tmpnam)
    exit 10
end

if ~open(tmpin,tmpnam,'R') then
do
    say 'Can not open 'tmpnam
    exit 5
end

done=false
do until eof(tmpin) | done=true
    line=readln(tmpin)
    if word(line,2)='packets' & word(line,3)='transmitted,' then
    do
        packets=word(line,4)
        done=true
    end
end

if packets = 0 then
do
    say host' not responding'
    error=5
end
else do
    say host' responding'
    error=0
end
close(tmpin)
delete(tmpnam)

exit error

