Skip to content

Instantly share code, notes, and snippets.

@kelapure
Created February 11, 2019 21:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelapure/ef79419796e35a68629a4e772e4646e4 to your computer and use it in GitHub Desktop.
Save kelapure/ef79419796e35a68629a4e772e4646e4 to your computer and use it in GitHub Desktop.
The script that executes any batch job on the PCF as a task, waits for the result and prints out associated logs
#!/bin/bash
APP_NAME=$1
CMD=$2
task_id=$(cf run-task $APP_NAME "${CMD}" | grep "task id:" | awk '{print $3}')
task_name=$(cf tasks $APP_NAME | grep "^$task_id " | awk '{print $2}')
task_status=$(cf tasks $APP_NAME | grep "^$task_id " | awk '{print $3}')
while [ $task_status = 'RUNNING' ]
do
sleep 1
task_status=$(cf tasks $APP_NAME | grep "^$task_id " | awk '{print $3}')
done
cf logs $APP_NAME --recent | grep "TASK/$task_name"
exit $([ $task_status = 'SUCCEEDED' ])
@kelapure
Copy link
Author

Credit to Oleg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment