Shell script to check current date file is created and with >0 kb or not for multiple directories

Hi All,

I am new in scripting and working in a project where we have RSyslog servers over CentOS v7 and more than 200 network devices are sending logs to each RSyslog servers. For each network devices individual folders create on the name of the each network devices IP addresses.The main challenge which I am facing I can not go inside the individual folder and check if the current date file is created or not and if created then it is >0 kb or not for all those directories. All those network devices use to send the logs on daily basis and daily at 12 AM new file creates with the current dd/mm/yyyy time stamp. I actually need help if this can be checked through a script and notify via email. Any help would be highly appreciated. Thank you.

Regards, Pinaki

Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.

Show what you tried and where you got stuck.

Aside from what RudiC already correctly stated: What do you mean that you "can not go inside a folder"? Does it mean that you don't have neither r- nor x-permission to access the folder?

Ronald

Hi Ronald,

Thank you for your reply. I have the permission for those folders to access but the main point where I am stucked is I can check the current date file size from a single folder but I need to check the current date file size for multiple folders. I have attached a screenshot where multiple folders are there and inside those folders current date files create.

Regards,
Pinaki

Hi Pinaki,

you can use

"find" command with options "-size"

.

To check if its today's file, create a dummy file with touch and use "newer" option of find.

Regards,
Ravi

I don't know what you mean by checking a size, but the usual way to retrieve the size for a single file, is to use the stat command. The way to use this command differs between Unix platforms, and I don't know CentOS, so you will have to look at the respective man-page.

Of course to do this to several files, you have to loop over the files. This can be done using the for loop of bash, or using the find command. The latter is particularily convenient, if you need to descend into subdirectories.

#!/bin/bash
_file="$1"
[ $# -eq 0 ] && { echo "Usage: $0 filename"; exit 1; }
[ ! -f "$_file" ] && { echo "Error: $0 file not found."; exit 2; }

if [ -s "$_file" ]
then
        echo "$_file has some data."
else
        echo "$_file is empty."
fi

Hi Ravi,

I have found this one but from this script while running I have to mention the file name. But what I actually require is to check the current date files size from multiple folders.

Regards,
Pinaki

---------- Post updated at 06:48 PM ---------- Previous update was at 01:41 PM ----------

Hi Rovf,

Yes I got some hints. It can be done through the for loop to check the files for multiple directories. Though I am new but yet I am just trying to create that. Thank you for your suggestion.

Regards,
Pinaki

How about the below code,

touch -d $(date "+%F") new0000

find . -newer new0000 -type f -size +0