LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-21-2009, 04:57 PM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

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?

Thanks.
 
Old 01-21-2009, 05:08 PM   #2
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,589

Rep: Reputation: 187Reputation: 187
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
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Faster and simpler:
Code:
shell$ stat -c%s /etc/fstab
915
 
Old 01-24-2009, 10:17 AM   #4
renjithrajasekaran
Member
 
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.
 
  


Reply


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 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
Shell script: how to check read only file mode. knockout_artist Linux - Newbie 2 11-01-2007 09:28 AM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 09:30 AM


All times are GMT -5. The time now is 08:41 PM.

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