This is a script that will remove files if the volume is greater than 85%. It works fine, however, I would like to see the output of the find command in the terminal and save it to a temp file as well. If I put a -verbose on the end of the gzip command, it goes verbose, but I would like to see the files before the zip, not after.
volume="vol10"
mountp="/casper/vol10"
filepath="/casper/vol10/casperfile/"
fileglob="/casper/vol10/casperfile/201*"
filetemp=$(mktemp /tmp/vol10cleanup.XXXXXX)
get_volpercent() {
{ read foo ; read foo; read size used avail prct mountpoint ; } < <(df -k ${mountp}/*)
printf "%s\n" "The Percentage of $volume is $prct"
}
cd $filepath
for filerm in execution order ; do
get_volpercent
if [[ "$prct" > "85%" ]] ; then
printf "%s\n" "Disk is over 85% full"
printf "%s\n" "find $fileglob/$filerm -mtime +10 -type f | xargs gzip "
printf "%s\n" "Zipping files"
find $fileglob/$filerm -mtime +10 -type f -print 2>&1 | tee -a $filetemp | xargs gzip
get_volpercent
else
get_volpercent
cat $filetemp
fi
done
How about using /dev/tty
for printing the filename to screen? And GNU Parallel for dealing with "ugly" filenames:
find $fileglob/"$filerm" -mtime +10 -type f -print | tee -a "$filetemp" /dev/tty | parallel gzip
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.