Hi Roger
Thanks for answering. I sent the message a number of times as it was not answered and a huge number of mails came in in the intirim causing my mail to be buried. This lessens the chance of me getting an answer.
The problem I have is that I don't want my password hardcoded anywhere in my scripts (for security). I want to telnet into the host and cd to a directory. So in essence I need to be able to interact with the script mid-script to send in my password and then return the script to doing its business

Here is how it can be done in tcl Expect:
#!/usr/dist/exe/expect -f set timeout -1 set hostname blah set login_name blah_blah spawn $env(SHELL) match_max 100000 send -- "telnet $hostname\r" expect "login:" send -- "$login_name\r" expect "Password:" interact -nobuffer -re "(.*)\r" return #ask user for password and then return to script send -- "cd $dir\r" interact
Now I am trying to translate this into perl (as tcl has some pecularities I don't really like. Heres what I came up with:
#!/usr/bin/perl use strict; use Expect; my $session = new Expect; my $server_connect = "blah"; my $username = "blah_blah"; my $shell_prompt= '(.*%|.*#|.*>|.*\\$) $'; my $dir="blah_blah_blah"; $session->spawn("bash"); print $session "telnet $server_connect\r"; $session->expect(60, -re, "ogin:"); print $session "$username\r"; $session->expect(10, -re, "assword:"); $session->interact(\*STDIN, "\r"); $session->expect(60, -re, "$shell_prompt"); print $session "cd $dir\r"; $session->interact();
The problem is that the line:
$session->interact(\*STDIN, "\r");
does not act in the same way as the line
interact -nobuffer -re "(.*)\r" return
does in tcl
I was wondering if anyone could elaborate why this is so?
thanks in advance

In reply to Re: Re: User interaction mid script again by markd
in thread User interaction mid script again by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.