-   Programming (
-   -   shell script - how to check file size (

noir911 01-21-2009 03:57 PM

shell script - how to check file size
I have a file that's supposed to be growing in size 24/7. I want to check every 10 minutes via cron that it's actually growing. If not, send an email. Does anyone know how to write a script to do that?


jailbait 01-21-2009 04:08 PM

Use the du command to get the file size and save the current size in a save file. At boot initialize the file size in the save file to 0 with a script in rc.local. Each 10 minutes have a cron job issue a du command, check the size against the size in your save file and if > then overwrite the save file with the new du value. If not > then send the email.

Steve Stites

Hko 01-21-2009 04:09 PM

Faster and simpler:

shell$ stat -c%s /etc/fstab

renjithrajasekaran 01-24-2009 09:17 AM

du file_to_be_monitored

This will give you the file size of the file you are interested in monitoring.

Write this value it to a txt file.

Every 10 mins - run the du command above and compare the value returned from it to the value in the text file we wrote to earlier.
If the values are different - overwrite it.
Else - fire a mail to the concerned person(s)


Linux Archive

All times are GMT -5. The time now is 07:25 PM.