March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Check if host is a live bash script

!/bin/bash
#
TCP-ping in bash (not tested)
HOSTNAME="$1"
PORT="$2"
if [ "X$HOSTNAME" == "X" ]; then
echo "Specify a hostname"
exit 1
fi
if [ "X$PORT" == "X" ]; then
PORT="22"
fi
exec 3<>/dev/tcp/$HOSTNAME/$PORT
if [ $? -eq 0 ]; then
echo "Alive."
else
echo "Dead."
fi
exec 3>&-

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>