gs1920-24hpv2 non-interactive ssh `invalid command`

R4scal
R4scal Posts: 2
edited April 14 in Switch

Hi

  1. when i logged in ssh session and execute `show system-information` - all works fine
  2. when i execute `ssh [email protected] show system-information` - Received disconnect from 192.168.0.254 port 22:2: invalid command system-information.

Is there any way to make this work?

All Replies

  • Zyxel小編 Lucious
    Zyxel小編 Lucious Posts: 279  Zyxel Employee

    Hi @R4scal


    Zyxel switch currently doesn't support such command to directly ask the info.

    It seems to us that your goal is to poll data from devices, our suggestion would be to use SNMP or create a script.


    Zyxel_Lucious

  • @Zyxel_Lucious Thanks for answer

    Any plans to add support of directly ask the info? It's really needed, because snmp doesn't have enough metrics about environment and poe ports

  • Zyxel小編 Lucious
    Zyxel小編 Lucious Posts: 279  Zyxel Employee
    edited November 2019

    Hi @R4scal


    There is no plan for this feature due to internal concern which involves security breach.

    For now, a script SSH is rather recommended for your demand.


    Zyxel_Lucious

  • Time for forum thread necromancy..

    I came across this problem, tried many methods to get around it. This one just about works but is unreliable. It looks like the switch might terminate the connection after the command has run but before all the command output has been sent over the SSH session.

    echo -e "show interfaces status\nshow version\n" | sshpass -p 'routerpasswordhere' ssh -v [email protected]
    Eventually I've found a reliable method is using the linux utility "expect". Here is a very simple example file. Make the file then chmod to +x and then run it. (obviously make sure you've installed expect (e.g. apt install expect).)

    #!/usr/bin/expect -f
    set username [lindex $argv 0];
    set ip [lindex $argv 1];
    spawn ssh [email protected]$ip
    expect "password: "
    send "INSERTPASSHERE\r"
    expect "# "
    send "show version\r"
    expect "# "
    send "show interfaces status\r"
    expect "# "
    send "show mac address-table all\r"
    expect "# "
    send "exit\r"

    I then call the script using ./switch_info_fetcher techsupport 10.11.12.4
    I hope the above advice helps someone else searching for the answers.