From: Chris M. <ch...@no...> - 2004-04-22 20:04:25
|
Hi, I recently came across Expect for Perl which I have opted to use as opposed to Net::Telnet. I was given the task to write a script which logs onto various nodes in our network and retrieves the configuration of them. I was using Net::Telnet but now the requirement to use SSH meant this was no longer possible. I have come across a minor little problem with terminal sizes, width in particular. It appears, by default to be setting the terminal width to 80 characters (or very close to this) unless I use clone_winsize_from. The clone_winsize_from appears to set the terminal settings to be the same as the calling terminal, but this is still not wider enough as the lines are still wrapping. I have looked on the web on Google, but cannot find any information on manually setting the width, is it possible to force the terminal width to some large number like 200 characters? I have included my code below (sorry if pasting is not permitted on this list). I have used the ps command as an example and piping towards more to make sure I can handle more prompts: #!/usr/bin/perl -w use strict; use Expect; $Expect::Exp_Internal = 0; $Expect::Log_Stdout = 0; my $ssh = "/usr/bin/ssh"; my $telnet = "/usr/bin/telnet"; (my $exp = Expect->spawn($ssh, "bob.test.sh")) || die "Couldn't spawn $ssh, $!"; $exp->exp_stty("raw -echo"); $exp->clone_winsize_from(\*STDIN); $exp->expect(10, [ qr/password:\s$/ ]) || die "Password prompt not found"; $exp->send("<password>\n"); $exp->expect(10, [ qr/bob.*[\]\$\>\#]\s$/ ]) || die "Prompt not found"; $exp->send("ps aux | more\n"); do { $exp->expect(10, [ qr/bob.*[\]\$\>\#]\s$/ ], [ qr/\e\[7m--More--\e\[27m/ ]) || die "Prompt not found"; print $exp->before(); if($exp->match =~ /\e\[7m--More--\e\[27m/) { $exp->send("\n"); } } while($exp->match =~ /\e\[7m--More--\e\[27m/); $exp->send("exit\n"); $exp->soft_close(); Thanks in advance, Chris |