I having a program that successfully uploads all of the files that I need. I have new files everyday that I need to upload. After I have uploaded the files I no longer need
Assuming that bar.txt and bar.txt.bak exist in a bucket s3://foo, "s3cmd ls s3://foo/bar.txt" shows a following output.
$ s3cmd ls s3://foo/bar.txt
2013-11-11 11:11 5 s3://foo/bar.txt
2013-11-11 11:11 5 s3://foo/bar.txt.bak
Since we should remove 2nd line from the command result, we use "awk" command to filter unnecessary lines.
$ filename=s3://foo/bar.txt
$ s3cmd ls ${filename} | awk "\$4 == \"${filename}\" { print \$4 }"
2013-11-11 11:11 5 s3://foo/bar.txt
Finally, we build up all commands.
filename=s3://foo/bar.txt
count=$(s3cmd ls ${filename} | awk "\$4 == \"${filename}\" { print \$4 }" | wc -l)
if [ $count -eq 0 ]; then
echo "file does not exist"
else
echo "file exists"
fi