Solved

Help with shell script

Posted on 2006-06-28
4
598 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
[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
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 250 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

636 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