重定向bas h的输出查找然后管道到xargs。

问题描述 投票:1回答:1

这是一个脚本,如果卷大于85%,将删除文件。它运行正常,但是,我希望在终端中看到find命令的输出并将其保存到临时文件中。如果我在gzip命令的末尾加上-verbose,它会变得冗长,但我想在zip之前看到文件,而不是之后。

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
bash xargs
1个回答
1
投票

如何使用/dev/tty将文件名打印到屏幕?和GNU Parallel用于处理“丑陋”的文件名:

    find $fileglob/"$filerm" -mtime +10 -type f -print | tee -a "$filetemp" /dev/tty | parallel gzip
© www.soinside.com 2019 - 2024. All rights reserved.