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
Solved

Help with shell script

Posted on 2006-06-28
4
594 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
Login Script to Copy Folders 12 41
Doc'in system (example?) BA 7 115
How to convert MFC::CString to UTF8 wchar_t* 10 275
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

791 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