Solved

need help with the watchmail command

Posted on 2009-04-05
9
275 Views
Last Modified: 2012-05-06
Hey, I need to implement a watchmail command in a shell, what its supposed to do is take a file name as an argument and beep if its size changes... I was thinking it could be done with a read file command and storing the number of bytes and check if it changes like that, is it that simple or a bit more complicated?
0
Comment
Question by:errang
  • 5
  • 4
9 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24070537
You can't simply depend on the file size changing ... What if a byte was simply overwritten (ie. not added or removed) ?

The most direct way to do that would be to hook into the system file operation calls, but that's rather complicated, and probably not what you'd like.

A good alternative however, is to watch the file modification timestamp, and see whether that changes.
0
 

Author Comment

by:errang
ID: 24070602
oh sweet... there's no built in command for that.. is there?
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24070820
What do you mean by a built-in command ? For doing what ?
0
 

Author Comment

by:errang
ID: 24070834
a built in command to get the time stamp, or do I just need to have the shell list everything about the file and parse the time stamp from that?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 24070870
You can use the stat function for that :

        http://linux.die.net/man/2/stat
0
 

Author Closing Comment

by:errang
ID: 31566713
Thanks, that function was not the first choice on my list... lol.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24072281
>> that function was not the first choice on my list... lol.

Why not ? Were you looking for something else ?
0
 

Author Comment

by:errang
ID: 24072290
no no... I thought I would have to use a file listing command, and somehow parse it... this was way better =D
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24072308
Heh. That's for sure - especially since the parsing would have to deal with possibly different output formats on different systems.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now