• C

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?
errangAsked:
Who is Participating?
 
Infinity08Connect With a Mentor Commented:
You can use the stat function for that :

        http://linux.die.net/man/2/stat
0
 
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
Increase Security & Decrease Risk with NSPM Tools

Analyst firm, Enterprise Management Associates (EMA) reveals significant benefits to enterprises when using Network Security Policy Management (NSPM) solutions, while organizations without, experienced issues including non standard security policies and failed cloud migrations

 
Infinity08Commented:
What do you mean by a built-in command ? For doing what ?
0
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.