PDA

View Full Version : Correct directory monitor command



apmperfmonitor
22-Sep-2015, 21:46
Hello Everyone,

Can someone help me to find correct SUSE command?

I am getting result 4096.

Command is

/bin/ls -ld <directory> | /bin/grep -v "^total" | /bin/sed 's/ */!/g' | /usr/bin/cut -d\! -f5,6,7,8,9

Thanks

APM

ab
22-Sep-2015, 22:31
This is a weird command. What are you trying to do, exactly?

Running on my system (openSUSE) I get this output:



2968!Sep!22!13:18!/home/ab


I cannot imagine how you would only get '4096' out of this unless your
'ls' command is significantly different from the norm.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
22-Sep-2015, 23:13
Thanks for your reply.

I work on monitoring tools. I am trying to configure remote monitor on HP Tool Called Site Scope to monitor remote directory.

What my tool does, It access with Linux account with /bin/bash shell and monitor remote directory.

We have Linus OS templates configured on monitoring server. Unfortunately don't have templates for SUSE.

Now requirement is my tool should monitor Directory and subdirectories to count all files.

Condition is

1) If files are more than 150 it should send alert .
2) Any file sits more than 4 hrs in any folder , Application owner need alert for that.


mon@app-new:~> /bin/ls -ld /mydir/* | /bin/grep -v "^total" | /bin/sed 's/ */!/g' | /usr/bin/cut -d\! -f5,6,7,8,9
4096!2014-01-23!18:22!/Mydir/a
4096!2014-02-18!15:54!/Mydir/b
4096!2014-02-18!15:54!/Mydir/c
4096!2014-01-23!18:22!/Mydir/d


But, I am getting just 4096 output instead of count.

ab
22-Sep-2015, 23:40
On 09/22/2015 04:14 PM, apmperfmonitor wrote:
>
> I work on monitoring tools. I am trying to configure remote monitor on
> HP Tool Called Site Scope to monitor remote directory.
>
> What my tool does, It access with Linux account with /bin/bash shell and
> monitor remote directory.
>
> We have Linus OS templates configured on monitoring server.
> Unfortunately don't have templates for SUSE.

The commands you are using are not distro-specific, so I am a bit
concerned they are not working for any distribution but more on that below.

> Now requirement is my tool should monitor Directory and subdirectories
> to count all files.
>
> Condition is
>
> 1) If files are more than 150 it should send alert .

Where are you counting files? Nothing about your command does this. Are
you trying to count the number, vs. the size, of files? I do not see that
happening either.

> 2) Any file sits more than 4 hrs in any folder , Application owner need
> alert for that.
>
>
> mon@app-new:~> /bin/ls -ld /mydir/* | /bin/grep -v "^total" | /bin/sed
> 's/ */!/g' | /usr/bin/cut -d\! -f5,6,7,8,9
> 4096!2014-01-23!18:22!/Mydir/a
> 4096!2014-02-18!15:54!/Mydir/b
> 4096!2014-02-18!15:54!/Mydir/c
> 4096!2014-01-23!18:22!/Mydir/d
>
>
> But, I am getting just 4096 output instead of count.

Are those directories, instead of files? If they are, then that would
explain things as a directory's size is not the size of everything within,
but is the size of the metadata required to store the directory
information (minimal) plus perhaps the link to contained files.

If you want to find only files, use 'find'. Using 'find' properly you can
probably do everything you want more-easily by setting size requirements
there too, and by using more-powerful commands like awk. For example to
only show file:



find /mydir -maxdepth 1 -type f -exec ls -l '{}' ';' | /usr/bin/awk
'{printf "%s!%s!%s!%s!%s\n", $5, $6, $7, $8, $9}'


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
23-Sep-2015, 03:07
Thanks again for your reply.
Yes. I want to monitor Directories and all subdir if numbr of files more than 150.

like MyDir/ApmMonitor/ and all sub-dir in ApmMonitor .

In short any of these dir having more than 150 files, command should catch.

ab
23-Sep-2015, 04:33
The command you're using will not do that; the number on a directory does
not indicate the number of files in a directory. You could still do this
with find/wc/awk/echo convolutions:



find /mydir -type d -exec bash -c "echo -n \$(find {} -maxdepth 1 -type f
| wc -l) && ls -ldn {} | /usr/bin/awk '{printf \"\!\%s\!\%s\!\%s\!\%s\n\",
\$6, \$7, \$8, \$9}' 2>/dev/null" \;


Note that command basically starts wherever you specify in the beginning,
and then recursively lists the number of files in each directory through
the directory structure, along with the rest of the output you were after.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
23-Sep-2015, 18:17
I am getting following output..

SiteScope@Servername:~> /bin/ls -ld /MyDir/Tina/* | /bin/grep -v "^total" | /bin/sed 's/ */!/g' | /usr/bin/cut -d\! -f5,6,7,8,9



4096!2014-01-23!18:22!/MyDir/Tina/abc

4096!2014-02-18!15:54!/MyDir/Tina/def

4096!2014-02-18!15:54!/MyDir/Tina/pqr

4096!2014-01-23!18:22!/MyDir/Tina/tom

4096!2014-02-18!15:54!/MyDir/Tina/get

How I will get just number of files with command instead list of sub dir.

Thanks

APM

ab
23-Sep-2015, 18:38
See the command from my previous response.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
23-Sep-2015, 19:34
Thanks again.

Are you pointing to this?

find /mydir -type d -exec bash -c "echo -n \$(find {} -maxdepth 1 -type f
| wc -l) && ls -ldn {} | /usr/bin/awk '{printf \"\!\%s\!\%s\!\%s\!\%s\n\",
\$6, \$7, \$8, \$9}' 2>/dev/null" \;


Is there any way I can get just number of files in format 15 or 50 or 150 instead of printing all subdir.

Regards

APM

ab
23-Sep-2015, 20:42
Perhaps I misunderstood what you meant by, "Now requirement is my tool
should monitor Directory and subdirectories to count all files."
Currently the command prints the number of files directly within each
subdirectory. If that is not what you're after, perhaps you can help me
understand better. You could add a '-maxdepth 1' to the first find
command to only show the top level of directories with their contents, and
you could remove the '-maxdepth 1' from the second find to then show the
count of files in all nested subdirectories, if that's what you want.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
23-Sep-2015, 20:58
hi,

Still I am getting following output with belwo command. I just need total number of files from home and subdir.

Apmmon@app-xop:/export/home> find -type d -exec bash -c "echo -n \$(find {} -type f | wc -l) && ls -ldn {} | /usr/bin/awk '{printf \"\!\%s\!\%s\!\%s\!\%s\n\",\$6, \$7, \$8, \$9}' 2>/dev/null" \;
1!2014-01-23!18:22!.!
!
0!2014-01-23!18:22!./qm4/DIN52002177!
0!2014-01-23!18:22!./qm4/MSC-2R0MBS1!
0!2014-01-23!18:22!./qm4/DIN52001822!
0!2014-12-05!14:27!./qm4/app-cud!
0!2014-02-20!18:01!./qm4/DIN52001589A!
0!2014-08-15!10:23!./qmm4/MSC2J4Z0P1!
0!2014-09-29!11:28!./qmm4/DIN51001139!
0!2014-02-18!15:54!./qm1!
0!2014-01-23!18:22!./qm1/app-cud.man.qa!
0!2015-03-11!16:14!./qm1/app-cud!
0!2014-02-05!11:14!./qnm4!
0!2014-01-23!18:22!./qnm4/app-cud.man.qa!
0!2014-09-22!09:36!./qnm4/app-cud!
0!2014-01-23!18:22!./edmo!
0!2014-01-23!18:22!./edmo/PUNDTL901811!
0!2014-01-23!18:22!./oaa!
0!2014-01-23!18:22!./oaa/MSC-2R0MBS1!

ab
23-Sep-2015, 21:39
It looks like your locale settings, or something else about your 'ls'
output, may be off. Have you verified that those subdirectories indeed
have zero files in them? If you want an alternate format, changing the
total output to ONLY have number of files and the path is much easier than
the original request:



find /export/home -type d -exec bash -c "echo -n \$(find {} -maxdepth 1
-type f | wc -l) && echo \" {}\"" \;


If you want to only look at top-level directories and find how many files
there are within all nested directories of those top levels (reporting
only the counts for the whole structure) you could use this:



find /export/home -maxdepth 1 -type d -exec bash -c "echo -n \$(find {}
-type f | wc -l) && echo \" {}\"" \;


On 09/23/2015 02:04 PM, apmperfmonitor wrote:
>
> hi,
>
> Still I am getting following output with belwo command. I just need
> total number of files from home and subdir.
>
> Apmmon@app-xop:/export/home> find -type d -exec bash -c "echo -n \$(find
> {} -type f | wc -l) && ls -ldn {} | /usr/bin/awk '{printf
> \"\!\%s\!\%s\!\%s\!\%s\n\",\$6, \$7, \$8, \$9}' 2>/dev/null" \;
> 1!2014-01-23!18:22!.!
> !
> 0!2014-01-23!18:22!./qm4/DIN52002177!
> 0!2014-01-23!18:22!./qm4/MSC-2R0MBS1!
> 0!2014-01-23!18:22!./qm4/DIN52001822!
> 0!2014-12-05!14:27!./qm4/app-cud!
> 0!2014-02-20!18:01!./qm4/DIN52001589A!
> 0!2014-08-15!10:23!./qmm4/MSC2J4Z0P1!
> 0!2014-09-29!11:28!./qmm4/DIN51001139!
> 0!2014-02-18!15:54!./qm1!
> 0!2014-01-23!18:22!./qm1/app-cud.man.qa!
> 0!2015-03-11!16:14!./qm1/app-cud!
> 0!2014-02-05!11:14!./qnm4!
> 0!2014-01-23!18:22!./qnm4/app-cud.man.qa!
> 0!2014-09-22!09:36!./qnm4/app-cud!
> 0!2014-01-23!18:22!./edmo!
> 0!2014-01-23!18:22!./edmo/PUNDTL901811!
> 0!2014-01-23!18:22!./oaa!
> 0!2014-01-23!18:22!./oaa/MSC-2R0MBS1!
>
>

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

apmperfmonitor
25-Sep-2015, 18:54
Thanks for your reply again.

I am getting following outputs.

Do you have any Shell scripts that check file count in directories and sub directories also age of the file more than 4 hrs - variable?

itescopemon@app-cud:~> find /export/ftpaccounts/image-processor/working/ -maxdepth 1 -type d -exec bash -c "echo -n \$(find {} -type f | wc -l) && echo \" {}\"" \;
1 /export/ftpaccounts/image-processor/working/
0 /export/ftpaccounts/image-processor/working/aaai
1 /export/ftpaccounts/image-processor/working/qlm1
0 /export/ftpaccounts/image-processor/working/bela
0 /export/ftpaccounts/image-processor/working/qim1
0 /export/ftpaccounts/image-processor/working/qmm1
0 /export/ftpaccounts/image-processor/working/indy
0 /export/ftpaccounts/image-processor/working/faao
0 /export/ftpaccounts/image-processor/working/qnm1
0 /export/ftpaccounts/image-processor/working/maa
0 /export/ftpaccounts/image-processor/working/nash
0 /export/ftpaccounts/image-processor/working/tbaa
0 /export/ftpaccounts/image-processor/working/aaa
0 /export/ftpaccounts/image-processor/working/kcaa
0 /export/ftpaccounts/image-processor/working/qim3
0 /export/ftpaccounts/image-processor/working/qmm3
0 /export/ftpaccounts/image-processor/working/qlm3
0 /export/ftpaccounts/image-processor/working/qnm3
0 /export/ftpaccounts/image-processor/working/naa
0 /export/ftpaccounts/image-processor/working/qim4
0 /export/ftpaccounts/image-processor/working/qlm4
0 /export/ftpaccounts/image-processor/working/qmm4
0 /export/ftpaccounts/image-processor/working/qm1
0 /export/ftpaccounts/image-processor/working/qnm4
0 /export/ftpaccounts/image-processor/working/edmo
0 /export/ftpaccounts/image-processor/working/oaa


sitescopemon@app-cud:~> find /export/ftpaccounts/image-processor/working/ -type d -exec bash -c "echo -n \$(find {} -maxdepth 1 -type f | wc -l) && echo \" {}\"" \;
0 /export/ftpaccounts/image-processor/working/
0 /export/ftpaccounts/image-processor/working/aaai
0 /export/ftpaccounts/image-processor/working/aaai/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/aaai/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/aaai/app-cud
0 /export/ftpaccounts/image-processor/working/qlm1
1 /export/ftpaccounts/image-processor/working/qlm1/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qlm1/DIN52001804
0 /export/ftpaccounts/image-processor/working/qlm1/MSC-DDGGDS1-L
0 /export/ftpaccounts/image-processor/working/qlm1/cp-appdev02
0 /export/ftpaccounts/image-processor/working/qlm1/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qlm1/app-cud
0 /export/ftpaccounts/image-processor/working/qlm1/DIN52001822
0 /export/ftpaccounts/image-processor/working/qlm1/leaf.sapphire
0 /export/ftpaccounts/image-processor/working/bela
0 /export/ftpaccounts/image-processor/working/bela/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/bela/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/bela/app-cud
0 /export/ftpaccounts/image-processor/working/qim1
0 /export/ftpaccounts/image-processor/working/qim1/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qim1/DIN52001804
0 /export/ftpaccounts/image-processor/working/qim1/DIN52002033
0 /export/ftpaccounts/image-processor/working/qim1/app-cud
0 /export/ftpaccounts/image-processor/working/qim1/DIN52001822
0 /export/ftpaccounts/image-processor/working/qmm1
0 /export/ftpaccounts/image-processor/working/qmm1/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qmm1/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qmm1/test_host
0 /export/ftpaccounts/image-processor/working/qmm1/PUNDTL905251
0 /export/ftpaccounts/image-processor/working/qmm1/app-cud
0 /export/ftpaccounts/image-processor/working/qmm1/DIN52001822
0 /export/ftpaccounts/image-processor/working/indy
0 /export/ftpaccounts/image-processor/working/indy/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/indy/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/indy/app-cud
0 /export/ftpaccounts/image-processor/working/faao
0 /export/ftpaccounts/image-processor/working/faao/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/faao/10.101.40.43
0 /export/ftpaccounts/image-processor/working/faao/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/faao/PUNDT08871
0 /export/ftpaccounts/image-processor/working/faao/PUNDTL901811
0 /export/ftpaccounts/image-processor/working/faao/app-cud
0 /export/ftpaccounts/image-processor/working/qnm1
0 /export/ftpaccounts/image-processor/working/qnm1/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qnm1/DIN52002177
0 /export/ftpaccounts/image-processor/working/qnm1/app-cud
0 /export/ftpaccounts/image-processor/working/qnm1/DIN52001822
0 /export/ftpaccounts/image-processor/working/maa
0 /export/ftpaccounts/image-processor/working/maa/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/maa/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/maa/app-cud
0 /export/ftpaccounts/image-processor/working/nash
0 /export/ftpaccounts/image-processor/working/nash/msc_jsachin
0 /export/ftpaccounts/image-processor/working/nash/MSC-411Y3R1-L
0 /export/ftpaccounts/image-processor/working/tbaa
0 /export/ftpaccounts/image-processor/working/tbaa/prepnixdqi01
0 /export/ftpaccounts/image-processor/working/tbaa/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/tbaa/MSC-CVANKALP
0 /export/ftpaccounts/image-processor/working/tbaa/MSC-PJAGDALELP
0 /export/ftpaccounts/image-processor/working/aaa
0 /export/ftpaccounts/image-processor/working/aaa/prepnixdqi01
0 /export/ftpaccounts/image-processor/working/aaa/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/aaa/PUNDT08871
0 /export/ftpaccounts/image-processor/working/aaa/DIN52001804
0 /export/ftpaccounts/image-processor/working/aaa/PUNDTL901811
0 /export/ftpaccounts/image-processor/working/aaa/DIN14001289
0 /export/ftpaccounts/image-processor/working/aaa/PUNDTL902167
0 /export/ftpaccounts/image-processor/working/aaa/DTPW7-PELAKSHM
0 /export/ftpaccounts/image-processor/working/kcaa
0 /export/ftpaccounts/image-processor/working/kcaa/prepnixdqi01
0 /export/ftpaccounts/image-processor/working/kcaa/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/kcaa/PUNDTL902167
0 /export/ftpaccounts/image-processor/working/kcaa/PUNLTR8LLDV6
0 /export/ftpaccounts/image-processor/working/kcaa/MSC-DDGGDS1-L
0 /export/ftpaccounts/image-processor/working/qim3
0 /export/ftpaccounts/image-processor/working/qim3/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qmm3
0 /export/ftpaccounts/image-processor/working/qmm3/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qmm3/DIN52002484
0 /export/ftpaccounts/image-processor/working/qlm3
0 /export/ftpaccounts/image-processor/working/qlm3/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qlm3/DIN52001804
0 /export/ftpaccounts/image-processor/working/qlm3/DIN52002259
0 /export/ftpaccounts/image-processor/working/qnm3
0 /export/ftpaccounts/image-processor/working/qnm3/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/naa
0 /export/ftpaccounts/image-processor/working/naa/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qim4
0 /export/ftpaccounts/image-processor/working/qim4/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qim4/MSC2J4Z0P1
0 /export/ftpaccounts/image-processor/working/qim4/app-cud
0 /export/ftpaccounts/image-processor/working/qim4/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qim4/DIN52002033
0 /export/ftpaccounts/image-processor/working/qim4/MSC-PJAGDALELP
0 /export/ftpaccounts/image-processor/working/qlm4
0 /export/ftpaccounts/image-processor/working/qlm4/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qlm4/PUNLTR8LLDV6
0 /export/ftpaccounts/image-processor/working/qlm4/MSC2J4Z0P1
0 /export/ftpaccounts/image-processor/working/qlm4/MSC-DDGGDS1-L
0 /export/ftpaccounts/image-processor/working/qlm4/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qlm4/MSC-GYBP1Q1-L
0 /export/ftpaccounts/image-processor/working/qlm4/app-cud
0 /export/ftpaccounts/image-processor/working/qlm4/LNAR-PBF04ZA
0 /export/ftpaccounts/image-processor/working/qmm4
0 /export/ftpaccounts/image-processor/working/qmm4/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qmm4/DIN52002177
0 /export/ftpaccounts/image-processor/working/qmm4/MSC-2R0MBS1
0 /export/ftpaccounts/image-processor/working/qmm4/DIN52001822
0 /export/ftpaccounts/image-processor/working/qmm4/app-cud
0 /export/ftpaccounts/image-processor/working/qmm4/DIN52001589A
0 /export/ftpaccounts/image-processor/working/qmm4/MSC2J4Z0P1
0 /export/ftpaccounts/image-processor/working/qmm4/DIN51001139
0 /export/ftpaccounts/image-processor/working/qm1
0 /export/ftpaccounts/image-processor/working/qm1/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qm1/app-cud
0 /export/ftpaccounts/image-processor/working/qnm4
0 /export/ftpaccounts/image-processor/working/qnm4/app-cud.man.qa
0 /export/ftpaccounts/image-processor/working/qnm4/app-cud
0 /export/ftpaccounts/image-processor/working/edmo
0 /export/ftpaccounts/image-processor/working/edmo/PUNDTL901811
0 /export/ftpaccounts/image-processor/working/oaa
0 /export/ftpaccounts/image-processor/working/oaa/MSC-2R0MBS1

ab
25-Sep-2015, 19:45
Find files older than four hours:



find /somepath -type f -mmin +240


--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...