Bash script to create tar.gz

Script to create tar.gz

Posted By: pmietlicki

Published to Linux on Jun 25, 2015

What we would like to do is to transfer with rsync some files in XML format. The script will have to parse a folder to find the last directory inside this folder (by date of creation) then inside this folder find files from a specific pattern and compress it inside a tar.gz.

Dans notre

#!/bin/bash

EXPORT_DIR=/appli/aaf/export/fichiers/ENTTSSERVICES
DEST=/appli/aaf/export/fichiers/ZEPHIR

# Retrieve the last directory inside EXPORT_DIR
LAST_DIR=$(ls -t $EXPORT_DIR | head -1)

# Construct the final path
SRC=$EXPORT_DIR/$LAST_DIR

#echo $PATH
#echo "Processing $i file..."
# Create the directory if not exist
mkdir -p ${DEST}
cd ${SRC}
# Get files with a specific pattern '9830' of XML type and get the first part (before _) of the filename
# We create a tar.gz archive inside the DEST folder
/usr/bin/find . -maxdepth 1 -name '9830????*.xml' | /usr/bin/cut -d_ -f 1 | /bin/sort -u |
while read rne; do
   /bin/tar -cvzf ${DEST}/"$rne".tar.gz "$rne"*.xml
done

Tags: AAF, eole, Zephir

Archive