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
|