• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 287
  • Last Modified:

need help with the watchmail command

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
errang
Asked:
errang
  • 5
  • 4
1 Solution
 
Infinity08Commented:
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
 
errangAuthor Commented:
oh sweet... there's no built in command for that.. is there?
0
 
Infinity08Commented:
What do you mean by a built-in command ? For doing what ?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
errangAuthor Commented:
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
 
Infinity08Commented:
You can use the stat function for that :

        http://linux.die.net/man/2/stat
0
 
errangAuthor Commented:
Thanks, that function was not the first choice on my list... lol.
0
 
Infinity08Commented:
>> that function was not the first choice on my list... lol.

Why not ? Were you looking for something else ?
0
 
errangAuthor Commented:
no no... I thought I would have to use a file listing command, and somehow parse it... this was way better =D
0
 
Infinity08Commented:
Heh. That's for sure - especially since the parsing would have to deal with possibly different output formats on different systems.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now