I am writing a script to tar a directory, then upload the tarball to S3. The directory is named based on a date, month-year. Here is my attempt:
TARNAME=`date --date="$(date +%Y-%m-15) -1 months" +' %B-%Y'`
tar cvfz /tmp/$TARNAME.tar.gz /Drive_E/drive_i_bu/monthly/$TARNAME
/usr/local/bin/aws s3 mv /tmp/$TARNAME.tar.gz s3://test-roger/
The above works, if I am not doing the variable substitution. WIth the variable, I get: tar: July-2016.tar.gz: Cannot stattar (child): /tmp/: Cannot open: Is a directory
Additionally, tar appears to try and dive deeper into the directory. Any ideas? Again, the above works without the variable substitution. So, the problem is not with the AWS CLI tool.
There is a space creeping into your
$TARNAME
(see below). This causes the/tmp/
andJuly-2016.tar.gz
to be treated as separate arguments by tarIf you get rid of that, things should work as you expect. It appears to be caused by the space in
Mind the white spaces:
tar cvfz /tmp/"${TARNAME}".tar.gz /Drive_E/drive_i_bu/monthly/"${TARNAME}" /usr/local/bin/aws s3 mv /tmp/"${TARNAME}.tar.gz" s3://test-roger/