• Catching a SSH error that seems non-existent

    From Luis Mendes@21:1/5 to All on Fri Oct 20 15:53:37 2023
    Hi,


    I've built a script to get some json array from another server.
    It should ssh as my user and do a "sudo su - -c 'some command'" in one
    swallow.

    When I run the entire command from the command line, no error is returned.
    echo $? returns 0.

    If I ssh to the machine first and then run the "sudo su - -c 'some
    command'", there's no error, too.
    echo $? returns 0.

    If I ssh to the machine, sudo su -, and only then execute the 'some
    command', no error is returned.
    echo $? returns 0.


    This is the section of the Tcl script where the call is made:

    set json ""
    if {[catch {exec ssh -T $master_server "sudo su - -c '$cmd'"} json ropts]}
    {
    puts stderr [dict get $ropts -errorcode]" ;# NONE
    puts stderr [dict get $ropts -errorinfo]" ;# returns the json
    array fine and the ssh banner text after it
    puts stderr [dict get $ropts -errorline]" ;# 32
    }

    Although
    1. This is working fine, as it returns the json array;
    2. I print to the screen the whole command, copy and paste it to another terminal and works fine, too;

    Why does the exec returns an error that is caught?
    Why is the error NONE?
    What is that 32nd line? If I count it from the beginning of the [dict get $ropts -errorinfo] output, it's just a json 'paramter: value' pair.

    I'm not understanding what is wrong.


    Luís

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luis Mendes on Fri Oct 20 16:10:29 2023
    Luis Mendes <[email protected]> wrote:
    set json ""
    if {[catch {exec ssh -T $master_server "sudo su - -c '$cmd'"} json ropts]}

    Why does the exec returns an error that is caught?

    I'm not understanding what is wrong.

    If you read the documentation for [exec] you will see that exec will
    also throw an error if the exec'ed process writes anything to the stderr stream.

    Is it possible that one of sudo, su, or 'cmd' writes something to
    stderr?

    Also, "sudo su" is extraneous, you really only need one or the other,
    not both together, to become root (provided 'sudo' is setup to let your
    regular user 'sudo' to root).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)