Posted on October 4, 2021 7:34 pm
 |  Asked by Weirong Jiang
 |  73 views
Tags:
RESOLVED
0
0
Print Friendly, PDF & Email

Hello, I was trying to run non-interactive CLI in cEOS and could not find much documents about it. According to its help,

bash-4.2# Cli –help

usage: Cli [-h] [-s SYSNAME] [-k SYSDBSOCKNAME] [-l] [–pdb] [-c COMMAND] [-A]

           [-M] [-e] [-E] [-p PRIVILEGE] [-i PLUGINS] [-I] [-G]

           [–startup-config] [–disable-autocomplete]

           [-T STANDALONE_SHELL_TIMEOUT] [–completions COMPLETIONS]

           [config-filename]

positional arguments:

  config-filename       Configuration filename to parse

optional arguments:

  -h, –help            show this help message and exit

  -s SYSNAME, –sysname SYSNAME

                        system name (default: ar)

  -k SYSDBSOCKNAME, –sysdbsockname SYSDBSOCKNAME

                        Specify the unix domain socket of the upstream Sysdb

                        process

  -l, –standalone      run in standalone mode (without Sysdb). Implies

                        –disable-guards.(also see –standalone-guards

  –pdb                 run under pdb

  -c COMMAND, –command COMMAND

                        run COMMAND non-interactively; separate multiple

                        commands with carriage returns

  -A, –disable-aaa     Do not communicate with the Aaa agent. This disables

                        authentication, authorization and accounting of

                        commands executed in this Cli instance.

  -M, –disable-automore

                        Do not apply paging filter for show commands executed

                        in this Cli instance.

  -e, –echo            echo commands when running non-interactively

  -E, –echo-timestamp  echo commands when running non-interactively, with

                        timestamps on each line.

  -p PRIVILEGE, –privilege PRIVILEGE

                        Start the session with this privilege level. Legal

                        values are 0-15 (default: 1)

  -i PLUGINS, –plugin PLUGINS

                        Load this plugin explicitly, and suppress normal

                        plugin search. May be specified repeatedly.

  -I, –no-plugins      suppress any plugins from loading

  -G, –disable-guards  Do not guard any commands.

  –startup-config      Enable flags required for parsing startup-config

  –disable-autocomplete

                        Any token that does not match exactly will not

                        expanded implicitly

  -T STANDALONE_SHELL_TIMEOUT, –standalone-shell-timeout STANDALONE_SHELL_TIMEOUT

                        Specify timeout for running standalone shell

  –completions COMPLETIONS

                        Print helps for input

 

However, I’m not sure how to insert carriage returns into the commands.

bash-4.2# Cli -c “show version”

cEOSLab

bash-4.2# Cli -c “show version \n show hostname”

> show version \n show hostname

% Invalid input at line 1

bash-4.2# Cli -c “show version \r show hostname”

> show version \r show hostname

% Invalid input at line 1

bash-4.2# Cli -c “show version \r\n show hostname”

> show version \r\n show hostname

% Invalid input at line 1

 

0
Posted by Debasish Paul
Answered on October 5, 2021 12:35 pm

Hi Weirong

You can either make use of Cli or Fastcli to run multiple commands from bash. Could you please try the below syntax and let me know if it works for you?

In my case i have am using Cli or FastCli to execute show clock and show extensions, as you can see below:

[admin@do393 ~]$ FastCli -p 15 -c $'show clock nn show extensions'
Tue Oct 5 12:29:34 2021
Timezone: UTC
Clock source: NTP server

Name Version/Release Status Extension
----------------------------- -------------------- ----------- ---------
TerminAttr-0.19.8-1.swix v0.19.8/1 A, F 10
TerminAttr-1.7.4-1.swix v1.7.4/1 A, I 25

A: available | NA: not available | I: installed | NI: not installed | F: forced
S: valid signature | NS: invalid signature
The extensions are stored on internal flash (flash:)

[admin@do393 ~]$ Cli -p 15 -c $'show clock nn show extensions'
Tue Oct 5 12:30:29 2021
Timezone: UTC
Clock source: NTP server

Name Version/Release Status Extension
----------------------------- -------------------- ----------- ---------
TerminAttr-0.19.8-1.swix v0.19.8/1 A, F 10
TerminAttr-1.7.4-1.swix v1.7.4/1 A, I 25

A: available | NA: not available | I: installed | NI: not installed | F: forced
S: valid signature | NS: invalid signature
The extensions are stored on internal flash (flash:)

Regards,
Debasish

0
Posted by Weirong Jiang
Answered on October 5, 2021 4:24 pm

Thanks Debasish. I tried the way you suggested but it did not work.

bash-4.2# FastCli -p 15 -c $'show clock nn show extensions'

> show clock nn show extensions

% Invalid input at line 1

bash-4.2# Cli -p 15 -c $'show clock nn show extensions'

> show clock nn show extensions

% Invalid input at line 1

 

 

2
Posted by Debasish Paul
Answered on October 6, 2021 5:00 am

Hi Weirong,

It looks like we have auto-ignored the backslash sign from my response post earlier, hence you didn't get the complete command as i intended to share.

What you need to do is add a backslash before "n" letter and re-execute the command and let me know how it goes.

Cli -p 15 -c $'show clock backslashn show extensions'
FastCli -p 15 -c $'show clock backslashn show extensions'

Regards,
Debasish

0
Posted by Weirong Jiang
Answered on October 7, 2021 9:37 pm

Yes it works! Thanks Debasish.

BTW I tried 'n' in my earliest attempts but I did not add the '$'. Thanks again for the help!

Post your Answer

You must be logged in to post an answer.