Solved

Perl Script please!

Posted on 1998-09-08
7
186 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
Comment Utility
use Net::Telnet;
0
 
LVL 4

Expert Comment

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

Tom
0
 

Author Comment

by:peimbert
Comment Utility
Hi Tom!

I have a question...
What is CRT, what language do you develope in, where can I find it?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:peimbert
Comment Utility
Could I please get a source code example?

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

Expert Comment

by:binkzz
Comment Utility
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
Comment Utility
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
Comment Utility
#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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now