monskie has asked for the wisdom of the Perl Monks concerning the following question:

im trying to connect to a machine thru telnet connection then once im connected and in the $ prompt already i have to run a command like $manage then when i run $manage command it should have an output like TeMIP> prompt then in this new prompt i will execute another command like TeMIP>show then this will ouput something. how can i run the $manage to go to the TeMIP> prompt and run a command?
#!/usr/local/bin/perl -w use Net::Telnet; $uID = "uname"; $uPASS = "pwd"; $telnet = new Net::Telnet ( Timeout=>20, Errmode=>'die', Prompt => '/\$ $/i'); $telnet->open('hpsgncw.sgp.hp.com'); $telnet->login($uID, $uPASS); print $telnet->cmd('manage'); print $telnet->cmd('exec manage'); print $telnet->cmd('show mcc 0');

Replies are listed 'Best First'.
Re: Telnet Connection
by jettero (Monsignor) on Dec 21, 2006 at 09:57 UTC

    I'm pretty sure the Net::Telnet docs cover everything you're trying to do here. But, it sounds like you just need to change your prompt detector. It's a regular expression so you can probably use something like Prompt => '/(?:\$|TeMIP>)\s*$/' and you're all set.

    -Paul