1828658 Members
1241 Online
109983 Solutions
New Discussion

Unix script

 
SOLVED
Go to solution
Rui Vilao
Regular Advisor

Unix script

Greetings,

Our HP-UX boxes are connected via the network to some equipment we manage.
We can open a telnet session on these equipments and enter some administrative commands:

telnet x.x.x.x
5 (access level)
xxxxxxxxx (password)
Maint

etc...

exit

I was asked to write a script to run on the HP-UX box to automate these procedures.

Any suggestions?

TIA,

Kind Regards,

Rui.

"We should never stop learning"_________ rui.vilao@rocketmail.com
4 REPLIES 4
Bernie Vande Griend
Respected Contributor

Re: Unix script

What type of equipment: servers, routers, switches?
For routers, switches, your best bet is to use expect and create an expect script that does this.
Here are some examples:
http://tcl.activestate.com:8002/resource/software/extensions/expect/

If its a server, I would suggest using remsh or ssh instead of passing passwords around.

You can try passing commands directly to the telnet sessions by redirecting commands to it, but that is difficult as telnet is interactive. Expect is the best way to anticpate what response you will have and issue the commands at the appropriate time.
Ye who thinks he has a lot to say, probably shouldn't.
harry d brown jr
Honored Contributor

Re: Unix script

You can also use perl and there is an "Expect.pm" available. Perl will be stronger than any shell script.

live free or die

harry
Live Free or Die
linuxfan
Honored Contributor
Solution

Re: Unix script

Hi Rui,

You could try something like

/Begin/
#!/usr/bin/sh
# here hostname is the name of the remote machine
# username is the name of the user
# password is the password of the user username

REMOTE=hostname
(sleep 5
echo username
sleep 5
echo password
sleep 15
echo "ls -ald /tmp"
sleep 5
echo exit) |telnet $REMOTE

/End/

this is to connect to regular servers, The same could be modified to connect to switches/routers etc.

The other option is to use expect and/or write perl program using expect.pm module.


-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Rui Vilao
Regular Advisor

Re: Unix script

First of all,

Bernie, Harry and Ramesh, thanks a lot
for your contribution!

Ramesh your solution is exactly what I was looking for.

Many thanks,

Kind Regards,

Rui.
"We should never stop learning"_________ rui.vilao@rocketmail.com