Help for Count number of files in certain time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help for Count number of files in certain time
# 1  
Old 12-07-2016
Help for Count number of files in certain time

Chaps, I need to count number of files in a remote directory from Linux (FreeBSD) as if 10 trace files (log files) been generated within 5min of time. So this is the script then I can setup a monitoring.

I came across with ls -1 \ip\d:\Logs | wc -l but then what else requires to check time stamp, maybe I should use if ...then

Really appreciated any feedback

Sam

Moderator's Comments:
Mod Comment edit by bakunin: added ICODE-tags

Last edited by bakunin; 12-07-2016 at 08:11 PM..
# 2  
Old 12-07-2016
Quote:
Originally Posted by samwijekoon
Chaps, I need to count number of files in a remote directory from Linux (FreeBSD) as if 10 trace files (log files) been generated within 5min of time.
I may be a bit slow, but i don't get what you want to do: get the log files of the last 5 minutes? Get the last 10 logfiles?

And this:

Quote:
Originally Posted by samwijekoon
Code:
ls -1 \ip\d:\Logs | wc -l

is similarly mysterious to me: first, this is not a script, it more (or less, in fact: rather the latter) looks like a single command (syntax errors notwithstanding). You can execute - if it is meant as a command - that only locally, so: do you want to execute it remotely or locally or what? Second, the "path" looks suspiciously like a Windoze path, not a UNIX path. Is this a Windows system and, if yes, what is the FreeBSD system you spoke about earlier? Third: what do you mean by "monitoring"? Should this repeated many times over? And, if yes, what exactly are you supposed to monitor: number of files, size of files, size of all files, size/number of files created since last run of script? Something different?

bakunin
# 3  
Old 12-08-2016
Quote:
Originally Posted by bakunin
I may be a bit slow, but i don't get what you want to do: get the log files of the last 5 minutes? Get the last 10 logfiles?

And this:



is similarly mysterious to me: first, this is not a script, it more (or less, in fact: rather the latter) looks like a single command (syntax errors notwithstanding). You can execute - if it is meant as a command - that only locally, so: do you want to execute it remotely or locally or what? Second, the "path" looks suspiciously like a Windoze path, not a UNIX path. Is this a Windows system and, if yes, what is the FreeBSD system you spoke about earlier? Third: what do you mean by "monitoring"? Should this repeated many times over? And, if yes, what exactly are you supposed to monitor: number of files, size of files, size of all files, size/number of files created since last run of script? Something different?

bakunin
Let me to explain, a Windows server generating trace files. F5 load balancer wants to monitor those files. F5 big-ip runs on Linux freebsd. So I try to run a script on F5 when the condition match it will take the Windows server out of availability pool based on monitoring condition.

Here is the condition to trigger:
If 10 files are created within last 5 minutes then monitor takes server offline. I can include this script in the F5 device. Size of trace decide by end server which is a Windows. Hope that little bit clearer

Last edited by samwijekoon; 12-08-2016 at 02:43 AM..
# 4  
Old 12-08-2016
Quote:
Originally Posted by samwijekoon
Let me to explain, a Windows server generating trace files. F5 load balancer wants to monitor those files. F5 big-ip runs on Linux freebsd. So I try to run a script on F5 when the condition match it will take the Windows server out of availability pool based on monitoring condition.

Here is the condition to trigger:
If 10 files are created within last 5 minutes then monitor takes server offline. I can include this script in the F5 device. Size of trace decide by end server which is a Windows. Hope that little bit clearer
OK, this makes it a bit clearer. In this case you only need to plug your monitor "sensor" into the file sending process, like this (pseudo-code, just to demonstrate the logic):

Code:
function send_file ()
{ 
   take timestamp of current time
   add timestamp to list of sent files
   send file
}

main ()
{
   create empty list of sent files
   while <list is shorter then 10>
   {
       if <any entry in list is older than 5 minutes>
            remove this entry from list
       endif
       if <server ordered a file>
            send_file()
       endif
   }
   take server offline   # loop is left only if 10 or more entries in list
}

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 12-08-2016
Great, is this the code I should try or do I need modification on this
# 6  
Old 12-08-2016
Quote:
Originally Posted by samwijekoon
Great, is this the code I should try or do I need modification on this
Honestly: i don't know. You gave a roundabout description of your requirement and i wrote a roundabout solution. To really implement this you will need to specify in much more detail what your requirement is.

For instance (one of the things needing clarification): what should happen after taking the server offfline? Wait for some time and put it online again? (If yes: how long would be "some time"?) Do nothing and leave it offline?

Another detail needing clarification: what is meant by "send file(s)"? Transfer it with scp/rcp/rsync/ftp/sftp/or the likes? Socket communication? Anything else?

In any case: what i wrote was pseudo-code, which just shows a possible logic and control flow of a program which has to be implemented. To actually implement it you need to select a programming language first which you want to use (i.e. "bash" or "Korn Shell" or "perl" or "ruby" or "python" or "whatever else you might want to use, version 3.141596", etc..

I hope this helps.

bakunin
# 7  
Old 12-08-2016
Ideally need bash, to check whether 10 files within 5min been created. If that's true then F5 big-ip actions to bring server out of the pool. Script should only check the condition. F5 will setup how frequent to check (every 5 sec) and take the action.

Actual files are generating on the Windows web server, itself location E:\logs

Hope that helps to help me further

Thanks

Last edited by samwijekoon; 12-09-2016 at 11:07 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to count the number of files moved?

I'm writing a script for searching substring in file content and then moving found files. So far I've wrote script shown below grep -lir 'stringtofind' $1 | xargs mv -t $2 How can i count number of files moved? (4 Replies)
Discussion started by: Kadikis
4 Replies

2. Shell Programming and Scripting

Count number of files

Hi All! I need to have a script that counts the number of files arriving in a landing directory, them some app pick these files to be processed and load to a DB. But this process is so fast that I am not able to count all the files arriving on a landing directory. Please can you help? My... (6 Replies)
Discussion started by: fretagi
6 Replies

3. Shell Programming and Scripting

Count the number of subset of files in a directory

hi I am trying to write a script to count the number of files, with slightly different subset name, in a directory for example, in directory /data, there are a subset of files that are name as follow /data/data_1_(1to however many).txt /data/data_2_(1 to however many).txt... (12 Replies)
Discussion started by: piynik
12 Replies

4. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

5. Shell Programming and Scripting

Count number of files and use result as variable

Hi there I have a .ksh script that I am using on an AIX ( Actual Level 5.3.10.0, Maintenance Level 5.3.0.0) where I am logging into a windows box, doing a file count on that server and returning the output to the UNIX session. I would like to exit the script at this point in time if the... (10 Replies)
Discussion started by: jimbojames
10 Replies

6. Shell Programming and Scripting

count of files and number of bytes

1) I need a shell code to count the number of files ( without directories or sub-directories ) in a directory given as arguments I tried this code but it didn't work , maybe I tried the wrong one: numOfFiles=`find $1 -type f -maxdepth 1 | wc -l` I found it in another thread in this site.. ... (17 Replies)
Discussion started by: jack1985
17 Replies

7. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

8. Shell Programming and Scripting

count number of files in a directory

what's the script to do that? i want to only count the number of files in that directory, not including any sub directories at all (5 Replies)
Discussion started by: finalight
5 Replies

9. Shell Programming and Scripting

Count the number of files in a directory

Hi All, How do i find out the number of files in a directory using unix command ? (14 Replies)
Discussion started by: Raynon
14 Replies

10. UNIX for Dummies Questions & Answers

Count number of files in subdirectories

Hello, I am new to unix and would like to have a count of all the files in the current directory as well as all the files in a subdirectory. The command I used was ls -R | wc -l but the number returned wasn't correct. Can someone please help? Thanks (2 Replies)
Discussion started by: cbeverly
2 Replies
Login or Register to Ask a Question