Solved

Perl Script please!

Posted on 1998-09-08
7
206 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 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

8 Experts available now in Live!

Get 1:1 Help Now