仅当文件大于特定大小时才如何执行cronjob? [英] How to perform a cronjob only when a file is greater than a certain size?

查看:100
本文介绍了仅当文件大于特定大小时才如何执行cronjob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本(授予Romeo Ninov的脚本)选择最新目录并执行 cp 操作:

The following script (credit to Romeo Ninov) selects the most recent directory and performs a cp operation:

dir=$(ls -tr1 /var/lib/test|tail -1)
cd /var/lib/test/$dir && cp *.zip /home/bobby/

请参阅:当另一个程序在另一个程序中如何使用cronjob会导致cronjob中的命令失败?对于上一个问题。

Please see: How can I use a cronjob when another program makes the commands in the cronjob fail? for the previous question.

我想对此进行修改,以使 cp 仅在.zip文件大于定义的大小时发生字节大小,例如28,000个字节。如果.zip文件较小,则不会复制任何内容。

I would like to modify this so that the cp only happens if the .zip file is larger than a defined byte size e.g. 28,000 bytes. If the .zip file is smaller, nothing is copied.

和以前一样,这会在 / var / lib / test / ***中发生* (其中****从 0000 FFFF 并每天递增) 。

As before, this would happen in /var/lib/test/**** (where **** goes from 0000 to FFFF and increments every day).

谢谢!

推荐答案

您可以在此重写脚本方式:

You can rewrite your script on this way:

dir=$(ls -tr1 /var/lib/test|tail -1)
cd /var/lib/test/$dir
for i in *.zip
 do
 if [ "$(stat --printf="%s" $i)" -gt 28000 ] 
  then cp $i /home/bobby
 fi
done

这篇关于仅当文件大于特定大小时才如何执行cronjob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆