[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Re: [olug] Expect script help...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
(I'm including the PerlMongers group on this too since Jay sent the
request to both the PM and OLUG mailing lists... --Dan)
<quote who="Jay Hannah">
> Can you show us what success looks like when you run through the entire
> process manually?
Ok, here is the script, the output of the login session is below the script
- --- begin script ---
#!/usr/bin/expect
#
# Call like this:
# login.exp [RemoteSystemName] [RemoteUserName]
#
# Description: Expect script to automate login to a remote
# UNIX system by way of an intermediate "PowerBroker" controlled
# server. Script also sets the $DISPLAY variable to the proper
# system for displays.
set timeout 30;
# Retrieve the remote system to login to...
set where [lindex $argv 0];
# Retrieve the user to login to the remote system as...
set who [lindex $argv 1];
set PowerBrokerUser "<PowerBrokerUserName>"
set PowerBrokerPwd "<PowerBrokerPassword>"
# Tell the local workstation to allow in
# the remote system for X displays
spawn xhost +${where}
set PowerBrokerServer "<Power.Broker.Server.Address>"
# Login to the PowerBroker server...
spawn /usr/bin/telnet ${PowerBrokerServer};
expect "ogin:"
send "${PowerBrokerUser}\n"
expect "assword:"
send "${PowerBrokerPwd}\n"
expect "$ "
# Get the IP address we are coming from to set the
# XWindows DISPLAY variable on the remote system properly
send "who am i\n";
expect "$ ";
set output_array [split $expect_out(buffer) "("]
set ip [lindex $output_array 1]
set output_array [split ${ip} ")"]
set ip [lindex $output_array 0]
set MYDISPLAY "${ip}:0.0"
send "pbrun -h $where $who ; exit\n";
expect "assword for ";
send "${PowerBrokerPwd}\n";
send "DISPLAY=${MYDISPLAY}\n";
interact
- --- End script ---
Here is the screen output of a sample run:
- --- Begin sample run ---
$ ./login.exp remoteserver dlinder
spawn xhost +remoteserver
spawn /usr/bin/telnet pbroker
Trying 10.20.30.40...
Connected to 10.2.124.63.
Escape character is '^]'.
SunOS 5.8
login: dlinder
Password:
Last login: Mon Aug 30 14:07:08 from 10.1.120.158
Sun Microsystems Inc. SunOS 5.8 Generic Patch October 2001
eutil008
V480 for Non-Production apps
$ who am i
dlinder pts/2 Aug 30 14:23 (10.1.120.158)
$ pbrun -h remoteserver dlinder ; exit
Enter password for dlinder:
[remoteserver:~]
$ DISPLAY=10.1.120.158:0.0
[remoteserver:~]
$
- --- End sample run ---
There you have it. Thanks everyone for your time, hope this can help
someone in the future.
So, can someone re-write this in Perl w/ the Expect module? :)
Dan
- - - - -
"I do not fear computer,
I fear the lack of them."
-- Isaac Asimov
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFBMzsqNiBNyqUzGb8RAljkAJ9XHaj/KZ/fHXuEDJnjVn4s0Gb/YwCdERD2
cDtTKhKlY+Bt7HPVf7ueTTY=
=Mev2
-----END PGP SIGNATURE-----