Move, unzip, backup

#!/bin/bash
set -xv
errdir=/apps/awd/RPMSReportParser/dist/error
attach=/apps/awd/rip-optumprod/poller/attach
backup=/apps/awd/rip-optumprod/pollerstage/backup/
log=~/catcher.log

exec >>"$log" 2>&1
date >>"$log"

cd $errdir

for i in *.zip*; do

       cp -p $errdir/"$i" "$backup";
       mv -f $errdir/$i "$attach";
       cd "$attach"
       rename 's/(.*).{15}/$1/' *
       /bin/unzip $attach/"$1" -od "$attach" && rm -f "$1";
       find "$backup" -type f -mtime +10 -name '*.zip*' -print0 | xargs -r0 rm --
done

I'm new at this but

file lands in this directory /apps/awd/ReportParser/dist/error/

I need to move the files that land in there which are like this -

2161V0WBAWD.zip_20190131170233

to here

/apps/awd/rip-optumprod/poller/attach

and unzip them.

Backing up and logging etc.

I thought this would be easy but I'm a moron it seems. Any suggestions ?

I get various errors when trying to use unzip and or rename the files with the .zip extensions etc.

With over 8 years as a member of UNIX.com and having started 20 other threads you aren't that "new at this".

And, as you well know, we have difficulty reading the diagnostic messages that are printed on your screen when you don't show us the exact commands you used and the exact diagnostics that were printed by the system. Without being able to see them we can make lots of wild guesses about what might be going wrong (which wastes our time and yours).

Please show us the diagnostic messages that were printed while your script was running (in CODE tags) and tell us what operating system you're using!

1 Like

On top of what Don Cragun already requested, pls. show how you call / run the script, so we know what $1 would expand to.
Why using rename ... * (i.e. rename every file in sight) inside a loop is difficult to understand for me, even more when it seems to rename to one single constant target file name. Without knowing the details, I guess unzip having problems working on the resulting gobbledigook.
How about running the script with the -x (xtrace) option set and posting the results?

1 Like