Count todays created files and old files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count todays created files and old files
# 1  
Old 08-17-2010
Count todays created files and old files

Hello experts,

I used following approach to get listing of all files of remote server.
Now I have remote server file information on same server.


Quote:
#Defining variables and assigning values
USR='admin'
PASSWD='abc'
HT='xyz.aaa.com'
FILE='S*.pdf
DIRNAME='/doc'

LsFiles()
{
ftp -n -i $HT <<end_ftp
user $USR $PASSWD
cd $DIRNAME
ls "-lrt *.pdf"
bye
end_ftp
}

LsFiles > list_of_files.txt
I am getting listing in the output.txt


Quote:
-rwxr--r-- 1 504 504 176201 Aug 17 19:28 1652001_5-31-2010.pdf
-rwxr--r-- 1 504 504 178860 Aug 17 19:28 1648403_5-31-2010.pdf
-rwxr--r-- 1 504 504 175665 Aug 17 19:28 1655876_5-31-2010.pdf
-rwxr--r-- 1 504 504 177563 Aug 17 19:29 1661000_5-31-2010.pdf
-rwxr--r-- 1 504 504 302814 Aug 17 19:29 1650920_5-31-2010.pdf
-rwxr--r-- 1 504 504 174484 Aug 15 19:29 1665618_5-31-2010.pdf
-rwxr--r-- 1 504 504 177675 Jun 15 19:29 1655604_5-31-2010.pdf
I want to count today's created files and old files.

I want to compare the numbers i.e. all files were created today
or there are also some old files in the list.

Could you pl. give me a clue?

Thanks in advance.

Thanks
# 2  
Old 08-17-2010
Try this:
Code:
ls --full-time | awk ' BEGIN{ "date \"+%F\"" | getline today } \
   { if($6 == today) ++nFileCreatedToday; else ++nOldFile } \
   END { nFileCreatedToday=0; nOldFile=0; print "Number of files created today:", nFileCreatedToday, "\nNumber of old files: ", nOldFile } '

Note: you need to issue "ls --full-time" instead of "ls -lrt" to get the file listing.

Last edited by kevintse; 08-17-2010 at 12:30 PM..
# 3  
Old 08-17-2010
Thanks Kevin for quick reply.

Code:
ls --full-time | awk ' BEGIN{ "date \"+%F\"" | getline today } \   { if($6 == today) ++nFileCreatedToday; else ++nOldFile } \   END { print "Number of files created today:", nFileCreatedToday, "\nNumber of old Files: " nOldFile } ''


The files are located in remote server.

Do you think above statement will work in FTP connection?
# 4  
Old 08-17-2010
OK, ssh to the remote server and get the file listing.

Code:
ssh user@server "ls --full-time /your/dir" | \
   awk ' BEGIN{ "date \"+%F\"" | getline today } \
   { if($6 == today) ++nFileCreatedToday; else ++nOldFile } \
   END { nFileCreatedToday=0; nOldFile=0; print "Number of files created today:", nFileCreatedToday, "\nNumber of old files: ", nOldFile } '

# 5  
Old 08-17-2010
Kevin Thanks again for quick reply.

I modified the script was per your suggetion.

The directory has 5000 files but still it says

Code:
Number of files created today: 0
Number of old files:  0

# 6  
Old 08-17-2010
Ensure
Code:
ssh user@server "ls --full-time /modify/this/to/your/directory/"

returns something.
# 7  
Old 08-17-2010
Code:
USR='admin'
PASSWD='abc'
HT='xyz.aaa.com'
FILE='S*.pdf
DIRNAME='/doc'
 
ssh $USR@$HT "ls --full-time /doc" | \
   awk ' BEGIN{ "date \"+%F\"" | getline today } \
   { if($6 == today) ++nFileCreatedToday; else ++nOldFile } \
   END { nFileCreatedToday=0; nOldFile=0; print "Number of files created today:", nFileCreatedToday, "\nNumber of old files: ", nOldFile } '

Returns
Code:
Number of files created today: 0
Number of old files:  0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find todays files

I am trying to find todays files only in the "root directories like /etc, /opt etc. I do not want to search in my home directory or any of its subdirectories. That's hard because a directory listing does not show the year? -rw------- 1 andy andy 22487 Oct 12 13:40 .xsession-errors ... (8 Replies)
Discussion started by: drew77
8 Replies

2. Shell Programming and Scripting

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (6 Replies)
Discussion started by: ram1228
6 Replies

3. UNIX for Dummies Questions & Answers

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (2 Replies)
Discussion started by: ram1228
2 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

6. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

7. Shell Programming and Scripting

Count for only todays files.

Hi, I unable to find the direct command get the total count for the below files with today date. ls -lrt c90.txt n5.txt t1.txt k3.txt h9.txt s1.txt n2.txt a123.txt -rw-rw-r-- kkk klkl 980 Apr 26 19:00 c90.txt -rw-rw-r-- kkk klkl 80 Apr 26 19:00 n5.txt -rw-rw-r-- kkk klkl 12890 Apr 26... (3 Replies)
Discussion started by: onesuri
3 Replies

8. UNIX for Dummies Questions & Answers

need to zip all the files excluding todays file

HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file.... (4 Replies)
Discussion started by: arumilli
4 Replies

9. Shell Programming and Scripting

Find files having todays date and hostname in its name.

Hello, I am quite new to unix/shell and want to write a script using bash which will process the files. Basically i want to search files having name as "date+hostname+somestring.out" i am using below variables and then will use them in find command :- TODAY_DATE=$('date +%d')... (5 Replies)
Discussion started by: apm
5 Replies

10. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies
Login or Register to Ask a Question