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

x
?
Solved

Help with shell script

Posted on 2006-06-28
4
Medium Priority
?
605 Views
Last Modified: 2013-12-26
I need to have a script that will automatically log into a network device, reset a port, and exit the network device.  The script will be passed three values - ip address, device password and port number.  The contents of the shell script are as follows:

telnet $1
<need a carriage return here>
cli                                    
su                                      
$2                  
admin                        
reset po = $3
hangup
exit  

I am not sure how to add a carriage return after each command.  I would appreciate any advice on how to do that and if there are any other commands I need to add to the script.
0
Comment
Question by:shannon_adams
  • 2
4 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 17006690
You are probably going to need to use 'expect' here, but it does depend on how your network device handles passwords.

Try

telnet $1 `cat <<EOF

cli                                    
su                                      
$2                  
admin                        
reset po = $3
hangup
exit  
EOF`

0
 
LVL 48

Expert Comment

by:Tintin
ID: 17006864
Ignore the above, it is incorrect.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 17007346
> .. but it does depend on how your network device handles passwords ..
telnet handles password, not the device, hence your're right that your're wrong ;-)
(well, heard of some insecure telnet version which accept passwords on streams instead of tty)

I agree that expect is the tool to use: http://expect.nist.gov/
0
 
LVL 4

Expert Comment

by:JulieBouillon
ID: 17009271
Hi,

It could easily be done in perl with the Net::Telnet module, see the simple example below:
#!/usr/bin/perl
use strict;
use Net::Telnet;

my $telnet = new Net::Telnet( Errmode=>'die',
                                       Prompt => '/\# $/i');
$telnet->open('yourhostname');
$telnet->login('user', 'password');
print $telnet->cmd('/usr/bin/pwd; ls');
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

916 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