Solved

Perl Script please!

Posted on 1998-09-08
7
200 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now