in reply to Matching prompt in Net::Telnet

It has been a long time since I used Net::Telnet, so excuse me if I am way off base here:

$prompt= '/\nseahawk\:\>$/'

Just can't recall whether you can hand in a regexp ... . Just a thought :-)

...the majority is always wrong, and always the last to know about it...

Replies are listed 'Best First'.
Re^2: Matching prompt in Net::Telnet
by kkarne (Novice) on Nov 08, 2006 at 20:26 UTC
    Somehow that doesn't work. If I specify
    $prompt= '/\nseahawk\:\>$/'
    it returns
    [/builds/htpc2003r1/base/menu]
    and what's surprising is that even the log is missing the output from who command
    [/builds/htpc2003r1/base/menu] seahawk:>
      Sure! Like an idiot I missed the fact that the regex would catch at the top before the 'who', though maybe adding a return .... . Like this?: $prompt= '/\nseahawk\:\>\n$/'

      Wish I knew what was at the end of that last prompt. If there is a '\n' there, this should work. Give it a try...

      ...the majority is always wrong, and always the last to know about it...

        Just looked at the CPAN docs for this mod. Shows this example:
        use Net::Telnet (); $t = new Net::Telnet (Timeout => 10, Prompt => '/bash\$ $/'); $t->open("sparky"); $t->login($username, $passwd); @lines = $t->cmd("who"); print @lines;

        Maybe use the list that comes back from your command to trim things down to what you want, like popping of the last line or two, then printing to your output.txt file yourself? If your not looking at that doc already, it is Here

        ...the majority is always wrong, and always the last to know about it...

        Errors out with "Command timed-out" msg. In case you wanto know the exact output from host message before and after who command, here's the output that's logged in out.txt
        Last unsuccessful login: Wed Nov 8 07:07:27 EST 2006 on /dev/pts/8 fr +om 10.100.150.42 Last login: Wed Nov 8 15:45:15 EST 2006 on /dev/pts/5 from 10.100.163 +.71 [YOU HAVE NEW MAIL] [/home/tstbld] seahawk:>cd /builds/htpc2003r1/base/menu [/builds/htpc2003r1/base/menu] seahawk:>who tstbld pts/0 Nov 08 09:48 (10.100.150.42) pkmsqa pts/1 Nov 08 07:40 (ma-lt4810.us.manh.com) pkmsqa pts/2 Nov 08 11:18 (10.100.150.11) pkmsqa pts/3 Nov 08 12:56 (10.100.162.43) tstbld pts/4 Nov 08 11:25 (10.100.162.30) tstbld pts/5 Nov 08 15:50 (10.100.163.71) tstbld pts/6 Nov 08 05:34 (10.80.12.129) tstbld pts/7 Nov 08 14:59 (10.100.150.33) [/builds/htpc2003r1/base/menu] seahawk:>
        I've already seen that doc. The problem is that I have to specify the right prompt for cmd otherwise it uses default prompt and doesn't return. And that's where I am having problems... specifying the correct pattern