0

Context:

I’m writing a script that monitors all SFPs on a Brocade SAN switch and needs to iterate over all FabricID contexts.

When I log into a FabricOS 8.2.2d (also with 9.0.1) device through SSH then type:

setcontext <FID>

then the command behaves properly.

But when (as part of my script) I try to run the same command non-interactively via:

ssh <username@hostname> setcontext <FID>

then I get the following error message:

rbash: setcontext: command not found

What puzzles me is that other commands, such as showsfp, switchshow (that I intend to run after setcontext) work in both cases. I don’t understand what’s special about setcontext that makes it impossible to run non-interactively.

EDIT: More findings using command -V (https://man.cx/command):

command -V sfpshow
sfpshow is hashed (/fabos/link_bin/sfpshow)

command -V setcontext
setcontext is a shell builtin

Could that explain why I can run the former but not the latter command through ssh?

breversa
  • 101
  • 6
  • For the record, I’ll be exploring this next: https://community.hpe.com/t5/hpe-eva-storage/hp-8-40-sanswitch-remote-commands/td-p/5204687 – breversa Jun 08 '23 at 07:52

1 Answers1

0

From the ssh manual:

If a command is specified, it will be executed on the remote host instead of a login shell.

A login shell will read some configuration files which usually set variables like $PATH, so when no login shell is invoked you usually end up with a different environment.

rbash indicates that on this machine a restricted bash is running, so the -l parameter of bash to invoke a login shell should work.

ssh <username@hostname> bash -l setcontext <FID>

Another option could be to use the full path to setcontext, since it's most probably the $PATH variable that is missing.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • THANK YOU for you reply! Unfortunately, bash isn’t installed on the device: `rbash: bash: command not found`. I also don’t know the full path to `setcontext`, and rbash prevents the use of `/` (slash) anyway. – breversa Apr 12 '23 at 14:30