So, I'm a complete newbie when it comes to scripting, like this is my first one. I have created the following script:
# This simply declares which states we are using to create tarballs from
for blah in ar ky ms ny;
do
# This will go into each tomcat-state directory and create a tarball in /home/ec-user for all files older than 90 days
find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 | xargs tar -cvzf /home/ec2-user/archive-${blah}.tar.gz;
# This creates a master archive tarball containing all the archive-state.tar.gz files
tar -cvzf /home/ec2-user/ebd-log-archives.tar.gz /home/ec2-user/archive-${blah}.tar;
# Since in step one, we archives all files older than 90 days, this step removes them.
# find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 -exec rm {} \;
# And since we have the master archive file, this removes the archive-state files
rm /home/ec2-user/archive-${blah}.tar.gz;
done
I have commented out the deleting of the logs for testing.
The problem is, when I get the master tarball, it only has NY in it, or whichever I put as my last in the loop (I tested this to make sure it wasn't just a odd NY thing)
Not sure what's going on, I tested it against an older script SIMILAR to this in wording on that server, and that one runs fine.
Edit: Thanks for the responses, I have updated the script to:
# This creates the master tarball we will be using
tar -cvzf /home/ec2-user/ebd-log-archives.tar.gz
# This simply declares which states we are using to create tarballs from
for blah in ar ky ms ny;
do
# This will go into each tomcat-state directory and create a tarball in /home/ec-user for all files older than 90 days
find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 | xargs tar -cvzf /home/ec2-user/archive-${blah}.tar.gz;
# This creates a master archive tarball containing all the archive-state.tar.gz files
tar -rvzf /home/ec2-user/ebd-log-archives.tar.gz /home/ec2-user/archive-${blah}.tar;
# Since in step one, we archives all files older than 90 days, this step removes them.
# find /var/www/apps/tomcat-${blah}/logs -type f -mtime +90 -exec rm {} \;
# And since we have the master archive file, this removes the archive-state files
rm /home/ec2-user/archive-${blah}.tar.gz;
done
I'll try running with this and posting an update
ny
.