'try to run traceroute in gcp airflow but getting error: "No such file or directory: 'traceroute'"
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 ?
Solution 1:[1]
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())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kunal Deo |
