1

Can somebody help me; I have a directory in which some times only one zip file is pressent and sometimes more zip files. In case of one zip file it has to be execute (unzip) in case there are more the one zip file the files need to be execute in order of oldest first. Can somebody give me a example

I already have a script but it only works if there is only one zip file, if there are more zip files in the map then the script won't work.

#!/usr/bin/env bash
MAGEPATH=/var/www/vhosts/httpdocs/bin/
BASEDIR=$(dirname $0)
cd $BASEDIR

file=*.ZIP
  if [ -f $file ]
    then
      echo $file "exist"
        cp $file ./backup
    unzip $file
    rm -f $file
   fi
   if [ -f *BASIC.XML ]
    then
    mv *_BASIC.XML BASIC.XML
   fi
   if [ -f *PRICES.XML ]
        then
        mv *_PRICES.XML PRICES.XML
   fi
   if [ -f *STOCKINFO.XML ]
        then
        mv *_STOCKINFO.XML STOCKINFO.XML
   fi
   if [ -f *STOCKINFOU.XML ]
        then
        mv *_STOCKINFOU.XML STOCKINFO.XML
   fi
    mv BASIC.XML BASIC_$(date +\%F-\%H-\%M).XML
    mv PRICES.XML PRICES_$(date +\%F-\%H-\%M).XML
    mv STOCKINFO.XML STOCKINFO_$(date +\%F-\%H-\%M).XML
    cp -f *.XML ./backup
    rm -f *.XML

1 Answer 1

-1
#!/bin/bash
cl=$(find <path> -type f -iname "*.zip"|wc -l )
if [ $cl -eq 1 ]
then
echo "Only one zip file present and we unzipping it"
find <path> -type f -iname "*.zip" -exec unzip {} \;
elif [ $cl -gt 1 ]
then
for g in $(ls -lt <path>/*.zip | awk 'END{print $NF}')
do
echo "More one zip file exsists and we are Unzipping the oldest zip file"
unzip  $g -d <destinationpath>
done
fi
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .