Bash Script Help

Hello, I am very new at Shell Scripting, just begining to learn a little. What I am trying to do is to ping a remote host. If the host is up and accepting pings, I want to connect via telnet. If it is down just end ofcourse. This is what I have so far

#! /bin/bash
echo "Input an IP address to Ping"
read IP
echo "How many times do you want to Ping?"
read Count
echo "Pinging $IP $Count times"
ping $IP -c $Count || { echo "Nobody Home Go Away" >&2; exit; }
rup $IP || { echo "Host is Up" >&2; exit; }

This will ping and report to the user if the remote host is up or down. What I am having trouble doing is going from a good ping to starting the telnet process.

Say I have a good ping. How do I say in script, if ping is good, then start telnet. Do I need to use some kind of varible? Please help.

Thank you very much.

Joe

You can check the packet loss %. If it is 0% packet loss, then you can start the next activities.

Regards,
Thobias

so just something like:

if packet loss = 0%
then ..................

yes. you can get the packet loss % from the output of the ping command and check whether the % of packet loss is 0.

I figured out what I was looking for. The output or state of the completed command is stored in $?

#! /bin/bash
echo "Input an IP address to Ping"
read IP
echo "How many times do you want to Ping?"
read Count
echo "Pinging $IP $Count times"
if [ $? = "1" ] ; then
echo "Remote Host is Down"
else
echo "host is up"
fi

Now the next question would be how do I start the telnet command like this:

else
echo "host is up" | telnet $IP

Is that how it would go?

you can use telnet. but you have to pass userid and give password.