Solved

Perl Script please!

Posted on 1998-09-08
7
227 Views
Last Modified: 2010-03-05
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
Comment
Question by:peimbert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1204773
use Net::Telnet;
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1204774
Download CRT, it will allow great amounts of scripting inside
telnet, such as automated logins, etc.

Tom
0
 

Author Comment

by:peimbert
ID: 1204775
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!

 

Author Comment

by:peimbert
ID: 1204776
Could I please get a source code example?

P.S.  this script will be run under UNIX.
0
 
LVL 4

Expert Comment

by:binkzz
ID: 1204777
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
 

Accepted Solution

by:
hedj earned 170 total points
ID: 1204778
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
 
LVL 84

Expert Comment

by:ozo
ID: 1204779
#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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question