简体   繁体   中英

Zip Up Files in Bash Shell Script

I am writing a Bash Shell Script on Solaris on trying to extract logs matching, CSIS_Log_D[YYYYMMDD]T[hhmmss].tms, and zipping them up.

I am having issues in trying to only extract the logs matching the file pattern.

mkdir $destinationPath/archive

# Locate logs match file pattern, move them to another place.
cd $sourcePath
for f in CSIS_Log_D*T*.tms
do 
cp $f $destinationPath/archive
done

zip -r "${PASTDATEforARCHIVE}TO${CURRDATEforARCHIVE}.zip" "$destinationPath/archive"

# Verify that zip has been created.
if [ -f "${PASTDATEforARCHIVE}TO${CURRDATEforARCHIVE}.zip" ]
then
    rm -rf $destinationPath/archive
else
    printf "Zip creation failed '%s'\n"
fi

您的cp命令缺少源代码。

cp "$f" "$destinationPath/archive"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM