Logging into device with other set of credentials


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Logging into device with other set of credentials
# 1  
Old 04-19-2013
Logging into device with other set of credentials

If I run the below code... it will login into the router and then changes to privilege mode and then stores the running configuration information to an array.
In this program, I have included the username and password .
In case the username and password is wrong.. it will re login for 2 times and then terminate the program.

Now instead of that.. I want to verify the username and password..

=> if the credentials are correct... then it should continue..
=> if the credentials are wrong(should not check for 2nd time... then it should check with other set of credentials(mentioned in the program..

I am confused to convert the below program as per my above requirement.




Code:
 use strict;
 use warnings;
 
 use Net::Appliance::Session;
 
 my $ios_device_ip = '10.250.249.215';
 
 my $ios_username        = 'cisco';
 my $ios_password        = 'cisco';
 my $ios_enable_password = 'cisco';

#my $user2 = 'newcisco';
#my $pass2 = 'newpass';
#my $enablepassnew = 'cisco'; 

 my $running_config_file = "$ENV{HOME}/running_config.txt";
 
 my $session_obj = Net::Appliance::Session->new(
Host => $ios_device_ip,Transport => 'SSH',  );
 
 # give verbose output whilst we run this script
 $session_obj->input_log(*STDOUT);
 
 # try to login to the ios device, ignoring host check
 $session_obj->connect(
     Name => $ios_username,
     Password => $ios_password,
     SHKC => 0
 );
 
 # drop in to enable mode
 $session_obj->begin_privileged($ios_enable_password);
 
 # get our running config
 my @running_config =  $session_obj->cmd('show running');
 
 # chop out the extra info top and bottom of the config
 @running_config = @running_config[ 2 .. (@running_config -1)];
 
 open(FH, "> $running_config_file")
   or die("Cannot open config file : $!");
 print FH @running_config;
 close FH;
 
 # close down our session
 $session_obj->close;

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to set colorscheme for a shell while/after logging in?

I am trying to put the below in a file .vimrc and sourced the file, however when i vi any file it is not showing/reflecting color scheme i wanted, Is there any way i can make this work? we use common application account to log in and by default it is CSH and later we change the shell to KSH. I want... (3 Replies)
Discussion started by: Ariean
3 Replies

2. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

3. UNIX for Advanced & Expert Users

Need to pass credentials in one Go

Hi, We usually switch user using the below command. sudo su - user1 It then prompts for the password which we feed in. I wish to pass both the username and the password in one go thus eliminating the prompt for the password. I am using java standalone to connect to unix using... (11 Replies)
Discussion started by: mohtashims
11 Replies

4. Shell Programming and Scripting

How to login with other set of credentials while remote logging?

Below is the code. I need to login into the router if the 1st set of credentials are correct.. if wrong... then it has to check with 2nd set of credentials.. => if the credentials are correct... then it should continue.. => if the credentials are wrong(should not check for 2nd time... then... (0 Replies)
Discussion started by: scriptscript
0 Replies

5. Red Hat

Unable To Activate Ethernet Network Device in RHEL 5.5 - e100 device eth0 does not seem to be presen

Hi All, Could anyone please help to resolve the below problem. I installed RHEL5.5 in my desktop.But when i try to activate the ethernet connection then it gives me the error. I spent 2 days for the above and go through with several suggestion found by googling. But no luck. ... (0 Replies)
Discussion started by: Tanmoy
0 Replies

6. Red Hat

set device mode permanently with udev rule

On a test server running CentOS 6, I try to permanently set the owner, group and mode of disk devices for use with a DB2 database. For this I created an udev rule file /etc/udev/rules.d/99-db2.rules: KERNEL=="sdb*", OWNER="db2usrl1", GROUP="db2adml1", MODE="0600" After a reboot, the owner and... (4 Replies)
Discussion started by: hergp
4 Replies

7. AIX

Telnet Credentials

Dears i am going to write a shell script to do some administration jobs and automate them , but i need to access remote servers through telnet so my question is how to pass the required credentials to telnet through shell script or can i use a file and redirect the standard input to be from that... (3 Replies)
Discussion started by: TheEngineer
3 Replies
Login or Register to Ask a Question