shell脚本监控某些文件夹下文件数量

网友投稿 606 2022-10-13

shell脚本监控某些文件夹下文件数量

shell脚本监控某些文件夹下文件数量

1.需求如下: 监控某些文件夹下的文件数量是否为某值,诸如/home/test1下文件数量是否为6,/home/test2下文件数量是否为6, 后续如果需要添加,直接修改checkFileNumber.txt文件。

[root@asm01 home]# cat checkFileNumber.txt /home/test1 5/home/test2 6/home/test3 7/home/test4 2 [root@asm01 home]# cat checkFileNumber.sh #!/bin/sh################################################################################################################Script name: checkFileNumber.sh#Script description: #Current Release Version: 1.0.0#Script Owner: He ,Haibo#Latest editor: He, Haibo#Support platform: Linux OS for redhat and centos.#Change log:#Descript:#################################################################################################################cat checkFileNumber.txt | while read linedo content_1=`echo $line | awk '{print $1}'` if [[ -d $content_1 ]];then content_2=`echo $line | awk '{print $2}'` num=`find $content_1 -type f -print | wc -l` if [[ $num -eq $content_2 ]];then echo "check $content_1 file number success" else echo "check $content_1 file number failed" fi else echo "directory $content_1 does not exist." fidone [root@asm01 home]# sh checkFileNumber.sh check /home/test1 file number successcheck /home/test2 file number failedcheck /home/test3 file number faileddirectory /home/test4 does not exist.

LINUX

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SourceKitten:一个可爱的小框架与命令行工具用于与SourceKit交互
下一篇:shell脚本获取oracle pdb
相关文章

 发表评论

暂时没有评论,来抢沙发吧~