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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to check current date file is created and with >0 kb or not for multiple directories
# 1  
Old 07-03-2018
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
# 2  
Old 07-03-2018
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.
# 3  
Old 07-04-2018
Quote:
Originally Posted by Pinaki
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
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
# 4  
Old 07-04-2018
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
Shell script to check current date file is created and with >0 kb or not for multiple directories-examplejpg
# 5  
Old 07-04-2018
Hi Pinaki,

you can use
Code:
"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
# 6  
Old 07-04-2018
Quote:
Originally Posted by Pinaki
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 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.
# 7  
Old 07-04-2018
Code:
#!/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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

3. Shell Programming and Scripting

Shell script replied multiple process for file has successfully created

Hi All, I have written the following code do FILE_NO=$(echo $LINE|awk -F"|" '{print $1}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') INST_NO=$(echo $LINE|awk -F"|" '{print $2}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') if ] then ... (3 Replies)
Discussion started by: yogendra.barode
3 Replies

4. Shell Programming and Scripting

Find the file created on current date

Hi All, I'm trying to find a file which is created on current day.... I searched in unix.com and i found, below command. find /land/ -mtime -1 -type f -print | grep "FF_Member_STG.dat" The command checks if the file with name "FF_Member_STG.dat" is created today then exit else proceed. ... (3 Replies)
Discussion started by: ace_friends22
3 Replies

5. Shell Programming and Scripting

Script to Search Logs Several Directories Pulling out Only Current Date

Hi All.. I'm seeking assistance with editing a script to search log files in several directories. I'm close to what I'm seeking, but need additional guidance. The log files are always listed by current date; however, inside the log file includes dates that go back to 2011. What I'm... (6 Replies)
Discussion started by: lenaf7
6 Replies

6. Shell Programming and Scripting

perl script to check if empty files are created and delete them and run a shell script

I have a local linux machine in which the files are dumped by a remote ubuntu server. If the process in remote server has any problem then empty files are created in local machine. Is there any way using perl script to check if the empty files are being created and delete them and then run a shell... (2 Replies)
Discussion started by: hussa1n
2 Replies

7. Shell Programming and Scripting

Shell Script to compare files, check current date and count

Hello - I have written the following basic shell script to count files, compare files and look for a particular strings in a file. Problem 1: How do I define more than 1 file location? #!/bin/bash #this is a test script FILES=$(ls /home/student/bin/dir1, home/student/bin/dir2)... (0 Replies)
Discussion started by: DallasT
0 Replies

8. Shell Programming and Scripting

Recursive call to find files and directories in Shell script from current path.

################################################################ Copy this script to your path from where you want to search for all the files and directories in subdirectories recursively. ################################################################# code starts here... (2 Replies)
Discussion started by: Ramit_Gupta
2 Replies

9. Solaris

check the current date file in directory

Hi, I am making a script which check the directory and if there is today date file, it is showing message file is there for today date . 1) filename is accessline.win.$timestamp example ;-accessline.win.200712211004 2) On monday i have recieved two file in this directory with current... (2 Replies)
Discussion started by: pallvi
2 Replies

10. Shell Programming and Scripting

how to check whether the given file is 5 weeks older than current date

HI, I need to check whether the given file is 5 weeks older than current date ?? Can anyone give me the script for this ?? (1 Reply)
Discussion started by: risshanth
1 Replies
Login or Register to Ask a Question