Count files every hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count files every hour
# 1  
Old 05-19-2010
Count files every hour

Hi,
I have a directory which uploads files every minute.I want to check the number of files uploaded for every one hour.
I want to run a cron every hour to chk this but iam hanged like how to write the script.

Like the script should count for one hr ie from 00:00 to 01:00 hrs then next hr when the cron is run shld chk for 01:00 to 02:00 hrs.
Can someone guide me to start writing this script.

Regards,
Nessj
# 2  
Old 05-19-2010
I have added a basic script . You can modify it as per your requirement and add it to cron to execute every one hour.Let us know if you have any further querry.

Code:
lst_count=`cat last_count`
new_count=`ls /PATH | wc -l`


nofilesupload=`expr $new_count - $lst_count`
time=`date`
echo "At $time $nofilesupload new files uploaded with in last HOUR" >> logs.txt

ls /PATH | wc -l > last_count

# 3  
Old 05-19-2010
This will fail at the first time since "last_count" file wont exists that time.

@nessj: Are you allowed to move files after each upload?

if yes, in that case, just count the files in upload_dir each hour and and then move the files to archive.
# 4  
Old 05-19-2010
Just add a if condition to check the file last_count.

Code:
if [ -f last_count ]
then
#nothing to do
else
echo "0" >>last_count
fi


Last edited by amitranjansahu; 05-19-2010 at 05:26 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

2. Shell Programming and Scripting

Command to find files older than 1 hour

Hi, Out of a list of files in a directory, I want to find the files which were created/modified more than 1 hour ago. I am using HP -UNIX and it does not support the argument -mmin. Please advise. I am using # !/bin/sh (4 Replies)
Discussion started by: jhilmil
4 Replies

3. UNIX for Dummies Questions & Answers

HP UNIX: How to find files which are older than one hour.

HP Unix Version: HP-UX B.11.31 U ia64 Question I look for script or command to find files which are older than one hour. Tried below; # set the file time to 1 hours ago touch -t 201307160700 ./touchfile find /app/grid/product/11.2.0.3/rdbms/audit -name '*.aud' -type f ! -newer... (4 Replies)
Discussion started by: Siva SQL
4 Replies

4. Shell Programming and Scripting

How to pick only the files which are generated in one hour?

Hello Masters, I need one help. I want to copy the files which are continuously generating on one server. But this would be on hourly basis. e.g. -rw-rw-r-- 1 akore akore 0 Feb 12 03:20 test1.log -rw-rw-r-- 1 akore akore 0 Feb 12 03:42 test2.log -rw-rw-r-- 1 akore akore 0 Feb 12 04:22... (2 Replies)
Discussion started by: akore83
2 Replies

5. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

6. Shell Programming and Scripting

Table with no of files every hour

Hello, In a HP-UX system we receive several files evry hour. The file is in the format filename+hour e.g: sv00 sv01 sv02 sv03 sv04 sv05 sv06 sv07 sv08 sv09 sv10 sv11 sv12 sv13 sv14 sv15 (2 Replies)
Discussion started by: drbiloukos
2 Replies

7. Shell Programming and Scripting

Grep string from logs of last 1 hour on files of 2 different servers and calculate count

Hi, I am trying to grep a particular string from the files of 2 different servers without copying and calculate the total count of its occurence on both files. File structure is same on both servers and for reference as follows: 27-Aug-2010... (4 Replies)
Discussion started by: poweroflinux
4 Replies

8. Shell Programming and Scripting

Find files modified in last hour sunOS 5.10

trying to find a way to locate files modified in the last hour in a shell script, unfortunately the command 'find . -mmin -60' is not supported on SunOS 5.10 (works on OpenSolaris 5.11 :mad:) Does anyone know a method of doing this in shell script on 5.10? cheers (19 Replies)
Discussion started by: rich@ardz
19 Replies

9. UNIX for Dummies Questions & Answers

To create alist of files created in the last 1 hour.

Hi, I need to create a script whcih ill run ever hour and will check all the files which are created in that hour for an error string. Need help in finding all the files which were created in the last 1 hour. Thanks in Advance. Asheesh (4 Replies)
Discussion started by: Asheesh
4 Replies

10. UNIX for Dummies Questions & Answers

display the files in a folder which are older than 1 hour

Hi, I have some files in a folder with different time stamps and I want to display the files which are older than 1 hour. i tried with find. need urgent help. (3 Replies)
Discussion started by: vgs
3 Replies
Login or Register to Ask a Question