Results 1 to 3 of 3
OK, I need help with a part of my script I am trying to make. What I have to do is to write a script to ping a host, and ...
- 12-07-2008 #1Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
Newb Need Help Bash Script
OK, I need help with a part of my script I am trying to make. What I have to do is to write a script to ping a host, and then if the host it up connect to it using telnet.
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; }
It works. It pings and lets the user know if the host is up or down. Now I am having trouble moving forward. If the host is up, I need to start the telnet part. So how do I say, if host is up, telnet? I basically need the bridge between the up host being pinged and starting the telnet part.
Thanks for any help in advance.
Joe
- 12-08-2008 #2
Welcome to the forums!
You will probably want to read the Advanced Bash Scripting Guide. Because an 'if' statement is indeed what you need here.
Something like this can work:
Oops, now I've written it for you. I hope it wasn't a homework question?Code:ping -c 4 $IP > /dev/null && VAR="1" || VAR="0" if [ "$VAR" -eq "1" ] ; then echo "Starting Telnet session. Are you sure you don\'t want to \'vim $0\' " echo "and change this to a SSH session\?" echo "Something can be said for good security practises, y\'know." telnet --all-options --all-extras $IP else echo "Seems they are out" exit 1 fi
Can't tell an OS by it's GUI
- 12-08-2008 #3Just Joined!
- Join Date
- Dec 2008
- Posts
- 4
Bash
This is what I got now:
#! /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
It works, I put in telnet $IP before fi, it seemed to work but I'm running Ubuntu in Virtual box and I can seem to ping any ip but my own local. I can get on the interent fine and everything, but if I try to ping google or anyone one it won't work. It tried google in windows and it pings fine. I guess i'll try a live cd.


Reply With Quote