[olug] Expect script help...

David Walker olug at grax.com
Fri Aug 27 01:14:24 UTC 2004


OK. If I understand correctly you are trying to parse the return value from 
the send "who am i\n" line

The following code splits on the open parentheses, takes the 2nd value, and 
then trims off the close parentheses.

set output "linderd     pts/2     Aug 26 10:32   (10.120.15.88)"
set output_array [split $output "("]
set ip [lindex $output_array 1]
set ip [string trimright $ip ")"]
set MYDISPLAY "${ip}:0"



On Thursday 26 August 2004 11:53 am, Daniel Linder wrote:
> Guy,
>
>   Slightly off-topic but I figgured what the heck. :)
>
> I am trying to automate login to a remote Unix system.  I have this
> working when my laptop telnets directly to the remote system and the
> expect script then ran a script on the remote server to set the $DISPLAY
> variable.
>
> The situation has changed and I now have to shell into an intermediate
> unix system, then run "PowerBroker" to connect in to the final location.
> When my script runs on the remote system now, it can only get the IP
> address of the intermediate "PowerBroker" system but not my true
> workstation.
>
> Can some expect or Tcl guru give me some quick pointers to parse the
> command output in the expect script to parse out my workstations IP
> address so I can send it to a remote system?
>
> Here is a snippet of my expect code:
>
>   #!/usr/bin/expect
>   #
>   # Code to login to the first machine would be here...
>   #
>   send "who am i\n";
>   # This returns:
>   # linderd     pts/2     Aug 26 10:32   (10.120.15.88)
>   set MYDISPLAY <what goes here?>
>   #
>   # Code to login to the second machine would be here...
>   #
>   # Now set my workstation DISPLAY variable...
>   send "DISPLAY=[ $DISPLAY ]:0.0\n";
>
> Thanks!
>
> Dan
>
> - - - -
> "I do not fear computer,
> I fear the lack of them."
>  -- Isaac Asimov
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug



More information about the OLUG mailing list