Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Perl Script please!

Hi, I need a perl or a shell (sh, csh, ksh, bash) script for Unix that emmulates a telnet command, send user name and password, loges in to root, and executes something.

in other words, I want to automatate the following commands with out being promped for nothing at all!

>>>>telnet server.com.mx
>>Login:
>>>>MyLogin
>>Password:
>>>>MyPassword
>>su -
>>>>RootPassword
>>>>Execute_Something
>>Exit

Thanks in advanced

Nadia
0
peimbert
Asked:
peimbert
  • 2
  • 2
  • 2
  • +1
1 Solution
 
ozoCommented:
use Net::Telnet;
0
 
binkzzCommented:
Download CRT, it will allow great amounts of scripting inside
telnet, such as automated logins, etc.

Tom
0
 
peimbertAuthor Commented:
Hi Tom!

I have a question...
What is CRT, what language do you develope in, where can I find it?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
peimbertAuthor Commented:
Could I please get a source code example?

P.S.  this script will be run under UNIX.
0
 
binkzzCommented:
You had me confused; thought this was windows telnet.

Nonetheless, I still have a unix telnet client source code if
you want it ?

Tom
0
 
hedjCommented:
Perl is really not a good language to do this in. However, there is another language called "Expect" which allows you to automate processes easily.  Here is an example expect script that would do precisely what you want:

#!/usr/contrib/bin/expect
set timeout -1
spawn telnet server.com.mx
expect "login: "
send "MyLogin\r"
expect "Password:"
send "MyPassword\r"
expect "Prompt String -- whatever it looks like"
send "su -"
expect "Password:"
send "Password"
expect "Prompt String again"
send "Execute some command\r"
send "quit\r"

Thanks.
0
 
ozoCommented:
#Perl has an Expect module too
use Expect.pm;
$p = Expect->spawn("telnet server.com.mx");
$p->expect(undef,"login");
$p->send_slow(0,"MyLogin\r");
@expectsend=(
  "Password:"=>"MyPassword\r",
  "Prompt String -- whatever it looks like"=>"su -",
  "Password:"=>"Password",
  "Prompt String again"=>"Execute some command\r",
);
while( @expectsend ){
  $p->expect(undef,shift @expectsend);
  $p->send_slow(0,shift @expectsend);
}
$p->send_slow(0, "quit\r" );
#should do the same thing

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now