How to find dependent tasks for a given DAG

Hi, I’m creating a bash script to validate the set of DAGs. I can get the DAG name by looping through the directory names. My question is how to get the task names for the given DAG and its dependencies?

For eg.
Dag Name : dag_1
Tasks : T1 >> T2 >> T3

I need the tasks names dynamically to pass to the below command
airflow dag_1 T1

Please share if you have answer.

You can use the dag and task objects to get this information

from airflow.models import DagBag

for dag in DagBag().dags.values():
  for task in dag.tasks:
    print (task.upstream_task_ids)
    print (task.downstream_task_ids)