Computing.Net > Forums > Solaris > Need some help on Unix script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need some help on Unix script

Reply to Message Icon

Name: getwithrob
Date: January 26, 2005 at 10:59:49 Pacific
OS: Solaris
CPU/Ram: 320R
Comment:

I'm terrible when it comes to Unix scripting so I'm asking for some help. I have a list of IP addresses sometimes up to 2 or 3 hundred. What I have to do is telnet to each device in the list. I made a file containing all of these devices and put a simple script to read each of the addresses. I looks like this:
$ more script
#!/bin/sh
for device in `cat /export/home/rjohnson/scriptstuff/file3`
do
telnet $device
done
$

How could I put something in this script to fail to the next device listed if unable to telnet to one of the devices in the file?

Here's what's up: There are some addresses in the file that are no longer used or are not reachable. When telnet gets to that address, it just keeps trying and trying. I end up doing a control C, deleting all addresses up to and including that one and starting the script over again.

Here's what else I'd like to do to this.

When you telnet to a device that has TACACs configured, it will prompt you for Username:. If TACACs isn't configured, it will prompt for Password:. I would like to have the script look at what is returned; Username: or Password:. If it is Username:, I'd like to have it put in my username which is johnsonr - I will type in the password for that username. If it prompts for password I'd don't want anything done...just wait for input at the keyboard (i.e. the password).




Sponsored Link
Ads by Google

Response Number 1
Name: cdac1000
Date: January 27, 2005 at 03:29:34 Pacific
Reply:

Can you not just ping to the systems ? or is logging in really nacessory?


0

Response Number 2
Name: David Perry
Date: January 27, 2005 at 06:02:04 Pacific
Reply:

The bourne shell does not lend itself well to interactivity as required by a telnet login. Have a look at expect.

The following is an sample expect script.

set username "johnsonr "
set password "password"
while { $n < 5 } {
spawn "/bin/sh"
send "telnet $HOSTNAME\r"
sleep 1
expect "ogin"
send "$username\r"
expect "Password"
send "$password\r"
send "\r\r"
"Welcome" {
incr pass0
set n 5
set p 0
close
}
"from" {
send "id\r"
expect {
$username {
incr pass0
set n 5
close
}
}
}
"login: $" {
set pass1 0
puts stdout "Expect return: $expect_out(0,string)"
puts stdout "Failed login"
send "\x1d\x0d"
expect "telnet"
send "close\r"
send "quit\r"
close
}
}
incr n
}


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


auto file transfer from u... mpstat & vmstat contr...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Solaris Forum Home


Sponsored links

Ads by Google


Results for: Need some help on Unix script

Unix script for find and replace www.computing.net/answers/solaris/unix-script-for-find-and-replace-/4401.html

How to install Solaris 8? www.computing.net/answers/solaris/how-to-install-solaris-8/154.html

Need help please! www.computing.net/answers/solaris/need-help-please/169.html