Start a Conversation

This post is more than 5 years old

Solved!

Go to Solution

22354

May 23rd, 2011 13:00

Script to SSH in to Switch

Hello Everyone,

Recently there's been lots of changes in my company, and they want to automate things by running scripts. I have a Brocade switch infrastruture with 2 48k and 2 5300's, 2 4900's and 4 4100's.

I need to create a shell script, so that I can remotly SSH in to switch, create zones, upload firmware and do most of the day to day stuff.

I am trying to write scripts but I cannot open SSH session for the swtichs from my unix terminal.

If anyone has done that and can let me know, how to SSH in to FC swtiches from a Shell Script and executes command that would be really apprecaited.

Thank You

Rama

141 Posts

December 12th, 2017 07:00

Hi there,

In our efforts to clean up the forum, we came across your question / statement.

If the question / statement is still valid, not expired and you need an update please reach out again and we try to get it answered.

As for now we will set it to “answered.”

Regards,

Jim

2 Intern

 • 

20.4K Posts

May 23rd, 2011 13:00

you should be able to simply ssh in like ssh admin@switch.com, the issue is that you need to setup ssh key authentication, otherwise you will be prompted to enter credentials. You need to research if you can setup ssh key based authentication on Brocade.

1 Rookie

 • 

66 Posts

May 24th, 2011 09:00

Hey, I did that. I enable SSH on the switch and then wrote a script and ran it on my linux terminal, but i still cannot connect to swtich. Any ideas??

The script which I worte to test:

#!/bin/bash
Server="10.200.11.10"  #Switch IP
USR="a-rmaddodi"        #user name
file="zone.txt"               # text file the i want to run. (zone.txt has one command in it which is #switchshow)
ssh $USR@$Server w > $file

Thank You

Rama

2 Intern

 • 

20.4K Posts

May 24th, 2011 11:00

Can you ssh into the switch from that unix box without using the script ?

1 Rookie

 • 

66 Posts

May 24th, 2011 12:00

Yes, I can ssh in to the switch with my script and without the script. And I can run all the commands, do zoning and most of the thing if I ssh in to the switch direclty. But the main issue is I cannot run any commands from my script. When I run my script, its lets me log in but my command never runs.

Have anyone tries this or anyone can have a sample script where you can log on to switch via SSH and also executes commands?

1 Rookie

 • 

66 Posts

May 24th, 2011 13:00

Yes, its did prompt me for password and I entered it and I can see the switch session, but logouts immediatly with out executing it.

My script:

#!/bin/bash

ssh username@switchIP 'commands'

and when I run this from the shell, its prompts me for the password, even after entering the password switch session opens but command doesnt run.

2 Intern

 • 

20.4K Posts

May 24th, 2011 13:00

i bet your script can't login to the switch, did you setup ssh key authentication so your ssh command does not get prompted for password ?

2 Intern

 • 

20.4K Posts

May 24th, 2011 14:00

try this:

[root@unix ~]$ ssh admin@192.168.1.50 "switchshow"
admin@192.168.1.50's password:
switchName:     myBrocadeswitch
switchType:     71.2
switchState:    Online
switchMode:     Native
switchRole:     Subordinate
switchDomain:   51
switchId:       fffc33
switchWwn:      10:00:00:05:1e:ed:a9:e2
zoning:         ON (brocade_fc1)
switchBeacon:   OFF

Index Port Address Media Speed State     Proto
==============================================
  0   0   330000   id    N8   Online      FC  F-Port  20:70:00:c0:ff:db:01:d1
  1   1   330100   id    N8   Online      FC  F-Port  20:70:00:c0:ff:da:c2:1b
  2   2   330200   id    N8   Online      FC  F-Port  24:70:00:c0:ff:da:c2:0f

5 Posts

June 2nd, 2011 22:00

Hi,

just some more thoughts on this, especially if you plan on doing this more regularly.

a) Really try ssh key authentication, although I don't know what FOS version you need to get this properly working with several users and keys. The way with directly editing the authorized_keys file on the brocade filesystem with the root account should work though, if it is supported.

b) look at expect[1]. I use pexpect in a python script with a config file where all switches are listed with tags like at which site they are located, type, fabric, ...

so you can conveniently run commands and queries against a specific subset of switches. If you do not use ssh key authentification without a passphrase be careful with the location and read access to the config file as you have to put the password in there.

Because you do not need to manually enter the password you can run some data for reporting via cron at night.

[1]  http://en.wikipedia.org/wiki/Expect

No Events found!

Top