1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

12 Comments

I have been trying to revert the job name to become a variable in itself for the delete to run off, however it doesn't seem to be working. Even with your new code, the issue still persists, even when I replace the '|' with a ";"
Why would you replace the | with a ;? That's back to square one; semicolon is syntactically equivalent to newline.
If I use a | it doesn't recognise it as code and gives me an error
What error? Why do you think it's not recognized as code?
It says aws: error: argument command: Invalid choice, valid choices are: followed by a large list of possible commands to use
|
0

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

2 Comments

I tried the following code but was given an error that I had received from a previous version I tried out. The error message is as follows: aws: error: argument command: Invalid choice,
use set -x at the top and see what's wrong there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.