Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-21-2009, 04:57 PM   #1
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
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?

Old 01-21-2009, 05:08 PM   #2
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Linux Mint 17, Debian 8
Posts: 7,863

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
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
Old 01-21-2009, 05:09 PM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
Faster and simpler:
shell$ stat -c%s /etc/fstab
Old 01-24-2009, 10:17 AM   #4
Registered: Jan 2009
Posts: 29

Rep: Reputation: 15
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

Last edited by renjithrajasekaran; 01-25-2009 at 04:07 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script: how to check read only file mode. knockout_artist Linux - Newbie 5 10-26-2015 12:56 AM
shell script to determine if file size equals zero jonfa Programming 5 12-11-2007 05:48 PM
File Size Shell Script BlackLabel Programming 7 11-27-2007 08:48 PM
Shell script problem. check file already exists sinister1 Linux - Server 8 11-20-2007 04:13 PM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 09:30 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration