Reputation: 133
I am trying to create a Bash Script that can delete all of my Amazon Transcribe jobs from a single command. I have created the following script:
#!/bin/bash
aws transcribe list-transcription-jobs --max-results 100 --query '[TranscriptionJobSummaries[*].TranscriptionJobName]' --output text
while read jobName; do
aws delete-transcription-job --transcription-job-name "$jobName"
done
However, when this runs, it lists the transcription jobs, but does not delete them. In fact, it does nothing at all after deleting the jobs! Although, it continues to process the job even through it does nothing.
Any ideas on how to fix this or where I am going wrong?
Upvotes: 1
Views: 163
Reputation: 189679
You need to pipe the standard output of the aws
command into the while read
loop's standard input. You'll also want to switch to read -r
to disable some legacy behavior of the read
command, though it probably doesn't matter here.
aws transcribe list-transcription-jobs --max-results 100 --query '[TranscriptionJobSummaries[*].TranscriptionJobName]' --output text |
while read -r jobName; do
aws delete-transcription-job --transcription-job-name "$jobName"
done
The crucial fix is the |
at the end of the first line. Maybe also read up on basic shell pipelines.
Your original command would simply list the resutls to standard output, then sit there and wait for the read
command to receive its input from somewhere else (realistically, from your keyboard).
If aws delete-transcription-job
can somehow accept a list of jobs, maybe you can do away with the while
loop entirely. I'm unfortunately not familiar with this specific command.
Upvotes: 2
Reputation: 1040
Simply
IFS="
"
for jobName in `aws transcribe list-transcription-jobs --max-results 100 --query '[TranscriptionJobSummaries[*].TranscriptionJobName]' --output text`; do
aws delete-transcription-job --transcription-job-name "$jobName"
done
Upvotes: 0