Posted on October 2, 2017 11:17 pm
 |  Asked by Eitan Akman
 |  1025 views
RESOLVED
0
0
Print Friendly, PDF & Email

Hi, 

In unix, there’s an environment variable called `?`. It stores the return code of the last cli command. If the value of `?` is anything other than zero, it means there was an error of some sort in the previous command. 

For example:

if I were to run:

unix> ls
my_dir1    my_dir2    my_file1    my_file2
unix> echo $?
0

`echo $?` returns zero because the previous command `ls` was successful. But if I had run a command which failed in some way, `?` would be set to a non-zero value. For example:

unix> bogus_command
-bash: bogus_command: command not found
unix> echo $?
127

 In this case, `echo $?` returns non-zero value (127) because `bogus_command` doesn’t exist and thus was not successful.

This is great for automation because you can tell if any command was successful without parsing the output of said command. Is there an analog for `?` in EOS? Or a way to determine whether an arbitrary command was successful or not?

I’m writing an automation script which takes an arbitrary set of commands and I’m trying to figure out a simple way to catch errors regardless of the command.

Thanks

 

0
Answered on October 22, 2017 5:44 am

 Hi  Eitan Akman,

I believe Arista CLI does NOT have an equivalent of the “?” command in Unix.

As described by you, you will have to parse the output for any errors.   

Please feel free to reach out to Arista TAC and they can create a Request for Enhancement (Feature Request) if required. 

Thanks!

0
Posted by Blake Gao
Answered on October 23, 2017 2:51 am

Hi Eitan

 

As mentioned above, Arista CLI doesn’t support it for the time being.

 

However,  I found everytime you failed to execute a command, the error message from the system would begin with “%” like below, and seems the normal output of a command wouldn’t include this.

 

switch(config)#show int e1/1

% Invalid input

 

Could you kindly make your system check the first character of the output and see whether it’s “%” or not to confirm if the command was executed successfully?

 

 

BR/Blake

Post your Answer

You must be logged in to post an answer.