Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

need help with the watchmail command

Posted on 2009-04-05
9
Medium Priority
?
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 

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
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

636 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