Solved

Help with shell script

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 78
lucky13 challenge 11 145
canBalance challenge 34 85
wordmultiple challenge 12 133
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

777 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