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.
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: