Brocade Fibre Channel Networking Community

Expand all | Collapse all

setcontext: command not found

  • 1.  setcontext: command not found

    Posted 05-24-2018 04:29 AM

    I have

     

    setcontext 61

    switchname

    logout

     

    in a file called test. When I run

     

    ssh myswitch

     

    I get

     

    -rbash: setcontext: command not found

     

    If I log on to the switch interactively the setcontext command works. Why doesn't it work from the file and what can I do to fix this issue? FOS 7.4.2a.

    Regards,

    Stuart


    #BrocadeFibreChannelNetworkingCommunity


  • 2.  Re: setcontext: command not found

    Posted 05-24-2018 04:35 AM

    @stuart.craig

     

    post please output of "lscfg --show"


    #BrocadeFibreChannelNetworkingCommunity


  • 3.  Re: setcontext: command not found

    Posted 05-24-2018 11:32 AM
    The scripts with "setcontext" would not execute. I've seen this many times.

    1) You either need to do setcontext manually and then execute the script - note that this needs to run from under the root account.

    2) Or you need to use "fosexec" in your script. But this has some other limitations.

    3) You might also configure a specific user account with specific home FID, then you might do what you are initially trying but without setcontext, as this specific user will be directly logging into the required context.
    #BrocadeFibreChannelNetworkingCommunity


  • 4.  Re: setcontext: command not found

    Posted 05-24-2018 11:43 PM

    Hello, 

     

    setcontext via script is working only when you switch to default admin domain first.

     

    test.h

      

    ad --select AD0
    setcontext 128

     

     

    Unfortunatelly right now i dont have any switch with VF enabled so im expecting output message that VF is not enabled.

     

    [marian.bezeg.xxxxxxx] ➤ X01 < test.sh
    
    -----------------------------------------------------------------
    lscfg_util: requires VF to be enabled.

    So it looks like that setcontext is now working.

     

     


    #BrocadeFibreChannelNetworkingCommunity


  • 5.  Re: setcontext: command not found

    Posted 05-25-2018 02:25 AM
    Marian, as far as I know VF cannot coexist with AD, e.g. see: "Virtual Fabrics must be disabled before you create Admin Domains"

    Are you sure that the command sequence you provided really helps to execute the "setcontext" in a script? Is it some kind of a undocumented workaround? I'd appreciate if you could share a bit more information on this. Thanks!
    #BrocadeFibreChannelNetworkingCommunity


  • 6.  Re: setcontext: command not found

    Posted 05-25-2018 04:12 AM

    Hello Alexey,

     

    as I mentioned, right now i don't have access to switches with VF enabled so i can't test it.

    Anyway AD0 is default AD which is there without any configuration on switches.

    You don't need to enable/create AD.

     

    I've tried this on switches where VF are disabled. I will really appreciate if someone will try it on switches where VF are currently enabled.

     

    I've tried to send setcontext without ad select:

    [marian.bezeg.**filtered**.xxxxxx] ➤ X05 < "setcontext"
    bash: setcontext: No such file or directory

    With AD select it will go ahead with setcontext command.

     

     

     

     


    #BrocadeFibreChannelNetworkingCommunity


  • 7.  Re: setcontext: command not found

    Posted 06-01-2018 05:18 AM

    My colleagues gave it a try and it didn't work:

     

    [user@host]# cat test111
    ad --select AD0
    setcontext 56

     

    [user@host]# ssh admin@switch < test111
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    admin@switch's password:
    Not allowed to execute in VF environment
    -rbash: setcontext: command not found

     

    As you can see, the "ad" command immediately fails because it can't be used in VF-enabled mode. Then "setcontext" fails as usual. Just in case, FOS is v7.4.2с here.


    #BrocadeFibreChannelNetworkingCommunity


  • 8.  Re: setcontext: command not found

    Posted 06-01-2018 07:35 AM

    Hello Alexey,

     

    many thanks for your test. So i go deeper in the switch config.

     

    At first the setcontext command is not linked its function itself. 

     

    switch: root> type setcontext
    setcontext is a function
    setcontext ()
    {
        if result=$(lscfg_util --switch $1); then
            eval "$result";
            execlogin;
        fi
    }

    Its stored in /etc/profile as global variable for interactive sessions. Unfortunatelly via remote sessions global variables are not loaded!

     

    So under root its not an issue.

     

    you may load global variables first and then execute setcontext.

     

    . /etc/profile
    setcontext 

    Question there is how to get it working without root account...

     

     


    #BrocadeFibreChannelNetworkingCommunity


  • 9.  Re: setcontext: command not found

    Posted 05-24-2018 04:47 AM

     lscfg --show

    Created switches FIDs(Domain IDs):  128(ds)(5)  61(53)  71(54)  13(55)
    Slot      1     2     3     4     5     6     7     8     9    10    11    12
    -------------------------------------------------------------------------------
    Port
     0    | 128 |  61 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
     1    |  61 | 128 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
     2    | 128 |  61 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
     3    |  61 |  61 |  61 |  61 |  61 |     |     |  61 |     |     |     |     |
     4    |  61 |  61 |  71 |  71 |  61 |     |     |  61 |     |     |     |     |
     5    | 128 |  61 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
     6    |  61 |  61 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
     7    | 128 | 128 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
     8    |  61 |  61 |  71 |  71 |  71 |     |     |  71 |     |     |     |     |
     9    |  71 |  71 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
    10    |  61 |  61 | 128 | 128 |  13 |     |     |  13 |     |     |     |     |
    11    | 128 | 128 |  61 |  61 | 128 |     |     | 128 |     |     |     |     |
    12    |  61 | 128 | 128 | 128 | 128 |     |     | 128 |     |     |     |     |
    13    | 128 |  61 |  61 |  61 | 128 |     |     | 128 |     |     |     |     |
    14    | 128 |  61 |  61 |  61 | 128 |     |     | 128 |     |     |     |     |
    15    | 128 | 128 |  61 | 128 | 128 |     |     | 128 |     |     |     |     |
    16    | 128 |  61 |  61 | 128 |  61 |     |     |  61 |     |     |     |     |
    17    | 128 |  61 |  61 | 128 |  61 |     |     |  61 |     |     |     |     |
    18    | 128 | 128 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
    19    | 128 | 128 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
    20    | 128 |  61 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
    21    | 128 | 128 | 128 | 128 |  61 |     |     |  61 |     |     |     |     |
    22    | 128 |  61 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
    23    |  61 |  71 |  71 | 128 |  71 |     |     |  71 |     |     |     |     |
    24    |  61 | 128 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
    25    | 128 | 128 | 128 | 128 |  71 |     |     |  71 |     |     |     |     |
    26    | 128 |  61 | 128 | 128 |  13 |     |     |  13 |     |     |     |     |
    27    | 128 | 128 | 128 | 128 | 128 |     |     | 128 |     |     |     |     |
    28    | 128 | 128 | 128 | 128 | 128 |     |     | 128 |     |     |     |     |
    29    | 128 | 128 | 128 | 128 | 128 |     |     | 128 |     |     |     |     |
    30    | 128 |  61 | 128 | 128 | 128 |     |     | 128 |     |     |     |     |
    31    |  13 |  13 |  13 |  13 | 128 |     |     | 128 |     |     |     |     |
    32    |  71 |  71 |  71 |  71 |     |     |     |     |     |     |     |     |
    33    |  61 |  61 | 128 | 128 |     |     |     |     |     |     |     |     |
    34    |  61 |  61 | 128 | 128 |     |     |     |     |     |     |     |     |
    35    |  61 |  61 | 128 | 128 |     |     |     |     |     |     |     |     |
    36    |  61 |  61 | 128 | 128 |     |     |     |     |     |     |     |     |
    37    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    38    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    39    |  61 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    40    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    41    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    42    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    43    | 128 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    44    | 128 | 128 |  61 | 128 |     |     |     |     |     |     |     |     |
    45    |  71 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    46    |  71 | 128 |  71 |  71 |     |     |     |     |     |     |     |     |
    47    |  13 | 128 | 128 | 128 |     |     |     |     |     |     |     |     |
    48    |     |     |     |     |     |     |     |     |     |     |     |     |
    49    |     |     |     |     |     |     |     |     |     |     |     |     |
    50    |     |     |     |     |     |     |     |     |     |     |     |     |
    51    |     |     |     |     |     |     |     |     |     |     |     |     |
    52    |     |     |     |     |     |     |     |     |     |     |     |     |
    53    |     |     |     |     |     |     |     |     |     |     |     |     |
    54    |     |     |     |     |     |     |     |     |     |     |     |     |
    55    |     |     |     |     |     |     |     |     |     |     |     |     |
    56    |     |     |     |     |     |     |     |     |     |     |     |     |
    57    |     |     |     |     |     |     |     |     |     |     |     |     |
    58    |     |     |     |     |     |     |     |     |     |     |     |     |
    59    |     |     |     |     |     |     |     |     |     |     |     |     |
    60    |     |     |     |     |     |     |     |     |     |     |     |     |
    61    |     |     |     |     |     |     |     |     |     |     |     |     |
    62    |     |     |     |     |     |     |     |     |     |     |     |     |
    63    |     |     |     |     |     |     |     |     |     |     |     |     |



    #BrocadeFibreChannelNetworkingCommunity


  • 10.  Re: setcontext: command not found

    Posted 06-06-2018 04:15 PM

    So, I know Brocade doesn't play well with redirects (< or >), so I wonder if that is the problem.

     

    On another note, I created a set of VBA scripts that use either plink or putty, depending on what I want to do.

     

    I would imagine that you could attempt something like this in your script:

     

    setcontext 61&&switchname&&logout

     

    The space between setcontext and 61 also might be an issue.

     

    "setcontext 61&&switchname&&logout" is another option.

     

    In my VBA scripts, quotes are a huge part of the whole ordeal.


    #BrocadeFibreChannelNetworkingCommunity


  • 11.  Re: setcontext: command not found

    Posted 06-06-2018 11:32 PM

    Hello,

     

    as i mentioned it not issue of spaces or wrong syntax.

    function setcontext is loaded from globalvariables once you open interactive session.

     

    During remote sessions variables are not loaded (so function as well) so it's not recognized by bash.

     

    All other command are created as links so there is no problem to access it as the env PATH is loaded during remote session.


    #BrocadeFibreChannelNetworkingCommunity


  • 12.  Re: setcontext: command not found

    Posted 06-07-2018 03:20 PM

    Well, since I just modified a script, and it worked...

     

            DoEvents
            Application.SendKeys ("setcontext 128")
            DoEvents
            Application.SendKeys ("~"), True
            DoEvents
            Application.Wait (Now + TimeValue("0:00:01"))

     

    Note the quotes.


    #BrocadeFibreChannelNetworkingCommunity


  • 13.  Re: setcontext: command not found

    Posted 06-07-2018 11:50 PM

    Hello,

     

    sure once you are not using remote shell but interactive it will works.

    The problem is once you are using remote shell it will not load variables from profile.

     

    KR 

     

    Marian


    #BrocadeFibreChannelNetworkingCommunity


  • 14.  Re: setcontext: command not found

    Posted 06-08-2018 03:19 AM
    Right, "expect" scripts would also work the same way.
    #BrocadeFibreChannelNetworkingCommunity


  • 15.  Re: setcontext: command not found

    Posted 04-24-2019 04:50 AM

    hi

    when using ssh the /etc/profile is not set  and you can't . /etc/profile because theres a / in there

    so

    you need to use  i.e

    ssh -f admin@$i fosexec --fid $virt -cmd "switchshow"

    where $i is your switch and $virt is the Fabric ID (virtual machine ) you want to see

    enjoy

     

     

     


    #BrocadeFibreChannelNetworkingCommunity