LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 03:57 PM   #1
noir911
Member
 
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?

Thanks.
 
Old 01-21-2009, 04:08 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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, 04:09 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Faster and simpler:
Code:
shell$ stat -c%s /etc/fstab
915
 
Old 01-24-2009, 09: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 03:07 AM.
 
  


Reply



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-25-2015 11:56 PM
shell script to determine if file size equals zero jonfa Programming 5 12-11-2007 04:48 PM
File Size Shell Script BlackLabel Programming 7 11-27-2007 07:48 PM
Shell script problem. check file already exists sinister1 Linux - Server 8 11-20-2007 03:13 PM
Need script to check file size. _TK_ Linux - General 1 08-06-2001 08:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:08 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
Open Source Consulting | Domain Registration