mardi 19 janvier 2021

Incorporating for-loop or if statement in Curl command

I am using below curl command to restart the Connectors/tasks. I have scheduled this curl command in Crontab. The purpose of this curl command is to restart the Connectors/Tasks, if their status is "Failure". I would like to incorporate "if" statement in this curl command, so that it attempts only 3 times in order to restart the Connectors/Tasks. After attempting 3 times, it has to stop the restarting the connectors/tasks and send an Email.

curl -s "http://localhost:8083/connectors?expand=status" | \
  jq -c -M 'map({name: .status.name } +  {tasks: .status.tasks}) | .[] | {task: ((.tasks[]) + {name: .name})}  | select(.task.state=="FAILED") | {name: .task.name, task_id: .task.id|tostring} | ("/connectors/"+ .name + "/tasks/" + .task_id + "/restart")' | \
  xargs -I{connector_and_task} curl -v -X POST "http://localhost:8083"\{connector_and_task\}

Aucun commentaire:

Enregistrer un commentaire