#!/bin/bash
for i in $(cat containers2.txt); do
swift list -A http://sslabapi/auth/v1.0 -U auto02 -K FfiBftkjgS8hnQn79Arj7PiHfvtsgn $i > js.txt
done
for a in $(cat js.txt); do
swift stat -A http://sslabapi/auth/v1.0 -U auto02 -K FfiBftkjgS8hnQn79Arj7PiHfvtsgn $i $a | xargs | awk '{if ($12 > 10000) print $2, $4, $6, $12, $15, $16, $17, $18}'
done
Above is a script I am working on. I apologize for how ugly it is, for I am not an expert with Bash Scripting. Ultimately I need to complete a loop where the containers.txt file has a list of containers like this:
5f7f720f-7563-031b-a002-9059f5c000b2
64366a18-e590-44cf-b99c-13b7587b34b5
6785038a-fd74-43c0-afcb-ddf25f251363
6952e11a-69a2-4988-81ff-10910a274d69
69f7d0f9-9a63-4d29-8e84-1c06b5fe892f
6a9480b8-84c8-4ab5-a82e-5576ceb1df7f
6bb37f24-1605-2aac-2ba2-c1e0d49f4ec7
874600f4-a8b2-4bf7-bca8-c75dac676f03
Each container has a list of objects as listed below:
ffd5eef3-2b75-4d4f-b30c-b9836b32a34c.FR.02
ffd5eef3-2b75-4d4f-b30c-b9836b32a34c.FS.02
Some containers have more objects then others. But in this script I am only getting the output of the final container written to the js.txt file. Also I am only getting the final output of the last objects in the final container. I am guessing the js.txt file is being overwritten each time the loop runs, so only the last container is present in it. Which makes sense to why the final output is only the objects from the final container.
Is there a way to output each object into js.txt one line at a time? Or am I going about this the wrong way?
Thanks
>>
instead of>
for redirection to add a content to a file instead of overwriting it, or even better place whole> js.txt
outside of the loop, afterdone
. – jimmij Feb 06 '19 at 16:23cat /dev/null > js.txt
to clear it out so that re-running the script will not just keep adding duplicates, and use>>
within yourfor
loops as @jimmij suggests. – DopeGhoti Feb 06 '19 at 16:30rm -f js.txt
. – Kusalananda Feb 06 '19 at 16:37