Skip to content

Instantly share code, notes, and snippets.

@pgbrandolin
Last active April 11, 2020 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgbrandolin/7595d4a369609db893d5616992940018 to your computer and use it in GitHub Desktop.
Save pgbrandolin/7595d4a369609db893d5616992940018 to your computer and use it in GitHub Desktop.
[w-edi-xml-archiver.sh] Walk a directory tree in Linux #linux #bash #find #spaces #experica
#!/bin/bash
#
#--- Path dello script ridefinito esplicitamente
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
#--- Directory base su cui avviene la scansione
export THEBASEDIR=/home/e-progen/experica/experica
#--- Data corrente
export THEDATE=$(date +%Y%m%d)
#--- URLPART: Componenti url (da completare con l'ambiente)
URLBASE=http://127.0.0.1:8080
URLPART=experica-sincro-edi-
DAYSKEEP=90
#--- Directory in cui risiede lo script
export MYDIR=$(dirname "$(readlink -f "$0")")
export MYLOG=${MYDIR}/logs
export LOGFILE="$MYLOG/$(basename "$0" .sh).log"
export ZONES="test uat prod"
export DIRECTIONS="in out"
#
#--- Test User--------------------------------------------------------------------
#if [ "$(whoami)" != "tomcat" ]; then
# echo "Script must be run as user: tomcat"
# exit -1
#fi
#--- Creazione della directory logs (se non esiste) ------------------------------
#if [ ! -d "$MYLOG" ]; then
# mkdir -p $MYLOG
#fi
#
#--- Log redirection -------------------------------------------------------------
#exec 3>&1 4>&2
#trap 'exec 2>&4 1>&3' 0 1 2 3
#exec 1>>$LOGFILE 2>&1
#
#---------------------------------------------------------------------------------
echo "_S_ START: $(basename "$0") at $(date)"
echo "=== Script is located in directory: $MYDIR"
#
#--- Processing Zones and Directions
#
for z in $ZONES
do
echo "=== Processing Zone : [ $z ]"
for d in $DIRECTIONS
do
echo " === Processing Direction [ $d ] for Zone: [ $z ]"
if [ -d ${THEBASEDIR}/${z}/${d} ]; then
find ${THEBASEDIR}/${z}/${d} -mindepth 3 -maxdepth 3 -type d -not -path "*/err/*" -print0 |
while IFS= read -r -d '' filep; do
pathlast=$(echo $filep |cut -sd / -f 7-)
filed=$(dirname "$filep")
dirnew=${filed}/${THEDATE}
# http://experica-sincro-edi/experica-sincro-edi-test/delete-older-than-90-days/in/desadv/0000000001/desadv1
# curl -s -H 'Cache-Control: no-cache' -A 'experica-sincro-edi'
theurl="${URLBASE}/${URLPART}${z}/delete-older-than-${DAYSKEEP}-days/${pathlast}"
echo curl -s -H 'Cache-Control: no-cache' -A 'experica-sincro-edi' " " ${theurl}
#printf 'FilePath %s\n' "$filep"
#printf 'FilePathL %s\n' "$pathlast"
printf 'TheURL %s\n' "$theurl"
done
else
echo "Directory ${THEBASEDIR}/${z}/${d} Not present. Skipping"
fi
done
done
#
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment