diff --git a/clear/main.py b/clear/main.py index 38dca2737..a8cf57f7f 100755 --- a/clear/main.py +++ b/clear/main.py @@ -79,21 +79,21 @@ def get_command(self, ctx, cmd_name): # location (configdb?), so that we prevent the continous execution of this # bash oneliner. To be revisited once routing-stack info is tracked somewhere. def get_routing_stack(): - cmd0 = ["sudo", "docker", "ps"] - cmd1 = ["grep", "bgp"] - cmd2 = ["awk", '{print$2}'] - cmd3 = ["cut", "-d-", "-f3"] - cmd4 = ["cut", "-d:", "-f1"] + result = 'frr' + + cmd0 = ["sudo", "docker", "ps", "--format", "{{.Image}}\t{{.Names}}"] + cmd1 = ["awk", '$2 == "bgp"'] + cmd2 = ["cut", "-d-", "-f3"] + cmd3 = ["cut", "-d:", "-f1"] + cmd4 = ["head", "-n", "1"] try: _, result = getstatusoutput_noshell_pipe(cmd0, cmd1, cmd2, cmd3, cmd4) - except OSError as e: raise OSError("Cannot detect routing-stack") return (result) - # Global Routing-Stack variable routing_stack = get_routing_stack() diff --git a/show/main.py b/show/main.py index 046b8d2d2..0935793de 100755 --- a/show/main.py +++ b/show/main.py @@ -82,8 +82,8 @@ # location (configdb?), so that we prevent the continous execution of this # bash oneliner. To be revisited once routing-stack info is tracked somewhere. def get_routing_stack(): - result = None - command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1 | head -n 1" + result = 'frr' + command = "sudo docker ps --format '{{.Image}}\t{{.Names}}' | awk '$2 == \"bgp\"' | cut -d'-' -f3 | cut -d':' -f1 | head -n 1" # noqa: E501 try: stdout = subprocess.check_output(command, shell=True, text=True, timeout=COMMAND_TIMEOUT)