Aqui está o script que você deseja. Apreciar!
#!/bin/bash
# License: GPL-2
# by desgua
# 2014 April 10
#
# This script is provided "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
#
# Always backup your files
# Alias for color
turquoise="3[01;36m"
yellow="3[01;33m"
blue="3[01;34m"
# Help
if [[ "$#" -ne "1" || "$@" == "-h" || "$@" == "--help" ]]; then
name=$(echo $0 | sed 's|.*/||')
echo -e "$turquoise\nUsage: $blue$name$yellow /folder/with/compressed/files\n
Please backup your files first!\n"
exit 0
fi
# Folder with the files
folder="$1"
# Make sure the folder exist
if [ ! -d "$folder" ]; then
echo -e "$turquoise\nI didn't find the folder $folder"
exit 1
fi
# Move into folder
cd "$folder"
# Make a trash folder
if [ ! -d trash ]; then
mkdir trash
fi
# Make sure not to mess with existing temp folder
if [ -d temp ]; then
echo -e "$turquoise\nThe folder temp already exist. I will move it to temp-old."
mv temp ./trash/temp-old
fi
# Create a working temp diretory
mkdir temp
# First extract all tar files from tgz files
for file in *.tgz; do
echo -e $turquoise "Extracting from $file..."
tar -xf "$file" -C ./temp/ --wildcards "*tar*"
tar -xf "$file" -C ./temp/ --wildcards "*OPP*xml"
done
# Move extracted files to the root of working diretory
find "$folder/temp/" -name '*.tar' -exec mv {} ./ \;
# Extract all log files from tar files
for file in *.tar; do
tar -xf "$file" -C ./temp/ --wildcards "*OPP*xml"
echo -e $turquoise "Extracting $file..."
mv "$file" ./trash/
done
# Make sure not to mess with existing folder
if [ -d logs ]; then
echo -e "$turquoise\nThe folder logs already exist. I will move it to logs-old."
mv logs ./trash/logs-old/
fi
# Create the logs folder
mkdir logs
# Move logs files to logs folder
echo -e $turquoise "Moving $file into folder ./logs/"
find "$folder/temp/" -name '*.xml' -exec mv {} "$folder/logs/" \;
# Clean up
mv temp/ ./trash/temp/
# Explain where to find the logs file
echo -e "$yellow\nThis script create a trash folder that you may want to delete now. It is $folder"trash/"
You will find your files into folder $folder"logs/"
"
# I didn't delete the temporary folders trying to make this script more safe
exit 0