Script to count files on daily basis


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to count files on daily basis
# 1  
Old 07-14-2015
Script to count files on daily basis

Hi all

I need to count files on a daily basis and send the output via email, what I am currently doing its simply running the following:
Code:
ls -lrt *.cdr | awk '{if(($6 == "Jul") && ($7 == "13")) print $0}' | wc -l

, which in this case it will count all files with extension "cdr" from the month of july, today the 13th of july.
I also use the same code to count files with extension "tap"
# 2  
Old 07-14-2015
Code:
find  -maxdepth 1 -name "*.cdr" -type f -mtime -1 | wc -l

Code:
ls -al --time-style=+%Y-%m-%d *.cdr | grep "2015-07-14" | wc -l


Last edited by Akshay Hegde; 07-14-2015 at 07:00 AM..
# 3  
Old 07-14-2015
Did you consider using the find utility with all its options and tests?
And, you could use awk to distinguish file extensions and do the counting per extension for you.
# 4  
Old 07-14-2015
the
Code:
find

example posted earlier is giving me a different output of my
Code:
ls -lrt *.cdr

command
# 5  
Old 07-14-2015
Assuming that you are looking for files dated yesterday (and not July 13 on any earlier years), you need to verify that there is a : in field 8. You could try something like:
Code:
ls -l | awk '
$6 != "Jul" || $7 != 13 || !($8 ~ /:/) { next }
/[.]cdr$/ { c++ }
/[.]tap$/ { t++ }
END { printf(".cdr: %d\n.tap: %d\n", c, t) }'

If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk.
This User Gave Thanks to Don Cragun For This Post:
# 6  
Old 07-14-2015
how do I send that output to an email address, like what would be the code to put in before
Code:
| mailx -s "yesterdays´s count" name@domain.com

---------- Post updated at 01:38 PM ---------- Previous update was at 12:39 PM ----------

Hi Don!

Sorry to disturb you, how mail that output using the mailxcommand

---------- Post updated at 02:24 PM ---------- Previous update was at 01:38 PM ----------

I have used the following code,:
Code:
END { printf(".cdr: %d\n.tap: %d\n", c, t) }' > file.tmp
if [ -s file.tmp ]
then
        mailx -s "count" name@domain.com <file.tmp
fi
rm file.tmp

but I am having the following error:
./veri[2]: syntax error at line 7 : `(' unexpected
# 7  
Old 07-14-2015
is END the 7th line of script?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

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

3. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

4. UNIX for Dummies Questions & Answers

Tracking the script(.sh) files triggered on daily or monthly basis from source

Hi Gurus, Is there any solution for tracking the script(.sh) files triggered on daily or monthly basis from source - Datastage (Routines) Needs to find out if this scripts are running on daily just want to know that is there anything to track Thanks in Advance (2 Replies)
Discussion started by: SeenuGuddu
2 Replies

5. Shell Programming and Scripting

Creating directory daily basis...

Need help on this script. the month is not changing to February... #!/bin/bash for X in `seq 1 100` do DATE=`date +%Y-%m-%d "--date=${X} day ago"` Y=`date +%Y` M=`date +%m` D=`date +%d "--date=${X} day ago"` DIR=/home/LogBackup for i in `seq 1 ` do if ;then # ... (1 Reply)
Discussion started by: alelee
1 Replies

6. Shell Programming and Scripting

Moving files on first in first out basis

suppose in a directory there are over 20 files. I need to move the first 10 files(first in first out basis, which ever files comes first) into a separate directory. i have an idea but not sure how far this is correct, can anyone guide me on this? find /opt/logs -name "cor*" -mtime 2... (6 Replies)
Discussion started by: venkatesht
6 Replies

7. Shell Programming and Scripting

Count first column on the basis of two other columns

Hello, I have a file ================= 12 SRV1 GRP1 19 SRV1 GRP1 19 SRV1 GRP2 3 SRV1 GRP1 3 SRV1 GRP2 30 SRV1 GRP2 7 SRV1 GRP1 8 SRV1 GRP3 =========== I want output like =============== 41 SRV1 GRP1 52 SRV1 GRP2 8 SRV1 GRP3 (1 Reply)
Discussion started by: kaustubh137
1 Replies

8. Shell Programming and Scripting

Zip all the files within a directory on a daily basis

I need to zip all the files within a directory on a daily basis and store them as a zip file within that directory with the date in its naming convention I have file extentions .log .lst and .out's within that directory How do i do this task zip -mqj mydir/allzip$YYMMDDDD.zip mydir/*.* ... (5 Replies)
Discussion started by: ramky79
5 Replies

9. HP-UX

HPUX printers & plotters disable on a daily basis

HI all, I've been having issues with printers and plotters disabling with no reason at all...It could happen to the same workstation once a day or once a week..There is nothing consistant..I stop and restart the spooler, only then can I re-enable the disabled printer.... If anyone is... (0 Replies)
Discussion started by: Shutdown
0 Replies
Login or Register to Ask a Question