try to run traceroute in gcp airflow but getting error: "No such file or directory: 'traceroute'"

562 Views Asked by At

we are trying to run trace route from airflow (in gcp) to get the output

traceroute = subprocess.Popen(["traceroute", '-w', '100','10.10.10.00'],stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

for line in iter(traceroute.stdout.readline,""):
    print(line)

but getting below error :

FileNotFoundError: [Errno 2] No such file or directory: 'traceroute'

is there any way to run traceroute from gcp airflow ?

1

There are 1 best solutions below

5
Kunal Deo On

You can use native Python to get the same result as traceroute. You can use pip package mtrpacket and then use the following code. To install a pip package use the PYPI PACKAGES tab from the composer UI.

This code will run without requiring root permissions.

import asyncio
import mtrpacket

async def trace():
    async with mtrpacket.MtrPacket() as mtr:
        for ttl in range(1, 256):
            result = await mtr.probe('172.217.160.206', ttl=ttl)
            print(result)

            if result.success:
                break

asyncio.get_event_loop().run_until_complete(trace())