1752800 Members
5621 Online
108789 Solutions
New Discussion юеВ

Re: Script help needed

 
kumardev
Occasional Advisor

Script help needed

Hi All,
I have a file which is actually an ls -lrt o/p of a particular directory like.
------------------
-rw-r--r-- 1 501 206 13 Mar 6 07:01 /var/archive/prodcomp/batchlog/tmpwrk_EXZPR00Bs.06rwc.03060702/tmpwrk_EXZPR00Bs.06rwc/startup_parms
146107 -rw-r--r-- 1 501 206 6 Mar 6 07:02 /var/archive/prodcomp/batchlog/tmpwrk_EXZPR00Bs.06rwc.03060702/tmpwrk_EXZPR00Bs.06rwc/runphase
146120 -rw-r--r-- 1 501 206 167 Mar 6 07:01 /var/archive/prodcomp/batchlog/tmpwrk_EXZPR00Bs.06rwc.03060702/tmpwrk_EXZPR00Bs.06rwc/parfile
146202 -rw-r--r-- 1 501 206 6 Mar 6 07:02 /var/archive/prodcomp/batchlog/tmpwrk_EXZPR00Bs.06rwc.03060702/tmpwrk_EXZPR00Bs.06rwc/smd_jobid
-----------------
I just want to know how to find out how many files are getting created on each and every day in the particular directory.

thanks for the answers

Regards
Dev
7 REPLIES 7
Steven E. Protter
Exalted Contributor

Re: Script help needed

Shalom,

Best to run with cron once a day.

cd
ls -1 | wc -l | mailx -s "daily file number report"

Run it the next day and do the math.

You can get more elaborate if you wish, but that is the basis.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Script help needed

Hi:

# cat ./tally
#!/usr/bin/perl
use strict;
use warnings;
my (@F, %day);
while (<>) {
next unless /^(-|d|l)/;
@F = split;
$day{sprintf "%3s %02d", $F[5], $F[6]}++
}
for (sort keys %day) {
print $_, ' = ', $day{$_}, "\n";
}

...

Run as:

# ./tally file

...or:

# ls -l /path | ./tally

Regards!

...JRF...
kumardev
Occasional Advisor

Re: Script help needed

acually i have run the command :-
find /var/archive/prodcomp/batchlog ! -type d -exec ls -lrt -print {} \; > /home/xosdj001/files

for getting the o/p in the files, now in the same file I want to know for each and every day how may files and are getting created(count) and what is the total size of within one day is getting generated.Which sud give me an o/p like:-
=============
Day Files_Generated Tot_siz_files
May 6 20 300 MB
May 7 15 250 MB
May 8 9 75 MB
.
.
.
.

=============

Thanks again

Regards
Dev
vinod_25
Valued Contributor

Re: Script help needed

Hi Dev

Add this script to your crontab to run daily and this script keeps updated copy of filesizes in bytes - convert to MB if you need by modifying the script.

echo "==============================================" > /tmp/file_list
echo "Day \t Files_Generated \t Tot_siz_files " >> /tmp/file_list
echo "==============================================" >> /tmp/file_list
for i in `ls -lrt /home/xosdj001/files | awk '{print $6}'| uniq`
do
for j in `ls -lrt /home/xosdj001/files | grep $i | awk '{print $7}'| uniq`
do
SUM=`ls -lrt /home/xosdj001/files | grep "$i" |awk '{sum = sum + $5} END {print sum}'`
NO=`ls -lrt /home/xosdj001/files | grep "$i" | wc -l`
echo "$i $j \t $NO \t\t $SUM" >> /tmp/file_list
done
done
echo "==============================================" >> /tmp/file_list



Cheers !!

Vinod

vinod_25
Valued Contributor

Re: Script help needed

Output looks like this

# cat /tmp/file_list
==============================================
Day Files_Generated Tot_siz_files
==============================================
Mar 17 1 256
Apr 23 45 536421
Apr 24 45 536449
==============================================
James R. Ferguson
Acclaimed Contributor

Re: Script help needed

Hi (again) Dev:

> I want to know for each and every day how may files and are getting created(count) and what is the total size of within one day is getting generated.

You _really_ should ask what you _really_ want at the onset. Use:

# cat ./tally
#!/usr/bin/perl
use strict;
use warnings;
my ( @F, $n, $sz, $key, %day );
while (<>) {
next unless /^(-|d|l)/;
@F = split;
$key = sprintf "%3s %02d", $F[5], $F[6];
$n = $sz = 0;
if ( exists $day{$key} ) {
$n = $day{$key}[0];
$sz = $day{$key}[1];
}
$n++;
$sz += $F[4];
$day{$key} = [ $n, $sz ];
}
for $key ( sort keys %day ) {
print $key, ' = ', $day{$key}[0], " -> ", $day{$key}[1], "\n";
}

...run as:

# ./tally file

Your output will look like:

Apr 01 = 5 -> 1387253
Apr 16 = 1 -> 100
Apr 17 = 1 -> 1024
Apr 19 = 2 -> 8218
Apr 23 = 3 -> 2964
Apr 24 = 1 -> 51366
Apr 29 = 1 -> 590
Aug 17 = 2 -> 2458
Feb 02 = 1 -> 104
Feb 14 = 2 -> 102792
Feb 17 = 1 -> 8192
Feb 23 = 1 -> 8192
Feb 29 = 1 -> 738
Jul 17 = 1 -> 266
Jul 29 = 1 -> 8192
Jun 29 = 2 -> 192
Mar 11 = 3 -> 1372132
Nov 11 = 2 -> 7651
Nov 14 = 1 -> 965
Oct 10 = 2 -> 290749

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Script help needed

Hi:

This version makes the formatting changes including the output in MB you wanted:

# cat ./tally
#!/usr/bin/perl
use strict;
use warnings;
my (@F, $n, $sz, $key, %day);
while (<>) {
next unless /^(-|d|l)/;
@F = split;
$key = sprintf "%3s %02d", $F[5], $F[6];
$n = $sz = 0;
if ( exists $day{$key} ) {
$n = $day{$key}[0];
$sz = $day{$key}[1];
}
$n++;
$sz+=$F[4];
$day{$key} = [ $n, $sz ];
}
print "Day #Files Total_Size\n------ ------ ----------\n";
for $key (sort keys %day) {
printf "%s %6d %7.0f MB\n" ,$key, $day{$key}[0], $day{$key}[1]/1024/1024;
}
1;

# cat ./tally

Your output will look like:

Day #Files Total_Size
------ ------ ----------
Apr 16 8 0 MB
Apr 17 6 103 MB
Apr 18 3 53 MB
Apr 19 6 148 MB

Regards!

...JRF...