nicky s
asked on
Need a python or any language script to copy yesterday files to a destination location and gzip them in destination directory
Need a python script to copy yesterday files to a destination location and gzip them in destination directory
or copy:
or move:
Better would be to have a small shell script: mgvzip.sh:
or more efficient to have a small shell script: multi-mgvzip.sh:
find "$sourcedir" -type f -mtime +1 -exec gzip <'{}' >"${targetdir}/$(basename {}).gz) \;
or move:
find "$sourcedir" -type f -mtime +1 -exec gzip <'{}' >"${targetdir}/$(basename {}).gz) \; -a -exec rm ${} \;
Better would be to have a small shell script: mgvzip.sh:
#!/bin/bash
src="$1"
trg="/where/ever"
nm=$(basename "${src}")
mv "$src" "$trg/" && gzip "$trg/$nm"
and call that with:find "$sourcedir" -type f -mtime +1 -exec mvgzip.sh "{}" \;
or more efficient to have a small shell script: multi-mgvzip.sh:
#!/bin/bash
trg="/where/ever"
while [ "$1" != "" ]
do
src="$1"
nm=$(basename "${src}")
mv "$src" "$trg/" && gzip "$trg/$nm"
shift
done
and call that with:find "$sourcedir" -type f -mtime +1 -print0 | xargs multi-mvgzip.sh
ASKER
Will it recursively search all directories for files inside source directory?
Find will unless you limit find to only do one level.
It will not recreate the tree on the target directory though... That requires a bit more involved scripting.
run find as a program with the "-exec ... \;" sequence replaced with -print to see what paths it finds,, like
It will not recreate the tree on the target directory though... That requires a bit more involved scripting.
run find as a program with the "-exec ... \;" sequence replaced with -print to see what paths it finds,, like
find "$sourcedir" -type f -mtime +1 -print
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window