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
# 8  
Old 08-17-2010
Smilie
Test the following command and ensure it returns the file listing.
I tested this on RHEL, it worked as expected.
Code:
ssh user@server "ls --full-time /home/"

# 9  
Old 08-17-2010
Question

Thanks Kevin for reply!!

I tried:

Code:
ssh admin@xyz.aaa.com "ls --full-time /doc/"

That works fine but when

Code:
ssh admin@xyz.aaa.com "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

# 10  
Old 08-17-2010
What platform is your remote server using? "ls --full-time" might produce something different on some UNIX systems, am not sure.
As on RHEL, I got
Code:
xxx.xxx.xxx.xxx [kevin ~]$ ls --full-time
total 5992
-rw-r--r--   1 kevin kevin      37 2010-06-04 09:06:37.000000000 +0800 abc2.txt
-rw-r--r--   1 kevin kevin      38 2010-06-04 09:06:18.000000000 +0800 abc.txt
....

You can see that 6th column of the listing is the create date of the file, so you need to compare this column to the "today" variable in the AWK script I offered. It might not be the 6th column in your case, but I am sure you are able to modify the script to make it work.
# 11  
Old 08-18-2010
Quote:
Originally Posted by dipeshvshah
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

Of course always get 0, because above red part. It reset the value to 0 in END sessions. They should be put in BEGIN session.

From your output file list_of_files.txt, use this :

Code:
awk '
BEGIN{ "date \"+%b %d\"" | getline today ;nFileCreatedToday=0; nOldFile=0;}
{ if("$6 FS %7" == today) ++nFileCreatedToday; else ++nOldFile}
END { print "Number of files created today:", nFileCreatedToday, "\nNumber of old files: ", nOldFile } 
' list_of_files.txt

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

# 12  
Old 08-18-2010
rdcwayx, Thank you.
It was my fault, I didn't test the script after adding "nFileCreatedToday=0; nOldFile=0;" to the script.
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