#!/usr/bin/bash
dev_type=${1}
host_name=${2}
target=${3}
dir_path=`dirname ${0}`
if [[ $(ps -ef|grep 'fetch_router_info.py'|grep ${host_name}|grep ${target}|grep -v grep|wc -l) -eq 0 ]];then
  if [[ "${1}" == "agent" ]];then
      timeout 2m python3 ${dir_path}/fetch_router_info.py ${1} --host ${host_name} --agent ${target} > ${dir_path}/netpath_result.log 2>&1 &
      echo "python3 ${dir_path}/fetch_router_info.py ${1} --host ${host_name} --agent ${target}" >> /tmp/fetch.query
  else
      timeout 2m python3 ${dir_path}/fetch_router_info.py ${1} --snmp-config /tmp/mac/snmp_info.json --host ${host_name} --ip ${target} > ${dir_path}/netpath_result.log 2>&1 &
      echo "python3 ${dir_path}/fetch_router_info.py ${1} --snmp-config /tmp/mac/snmp_info.json --host ${host_name} --ip ${target}" >> /tmp/fetch.query
  fi
  echo 'OK'
else
  echo '上个进程没有完成，关闭当前任务'
  exit 1
fi
