If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > monitoring a file and printing using command line arguments

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-04, 04:18
bubu bubu is offline
Registered User
 
Join Date: Aug 2004
Posts: 1
monitoring a file and printing using command line arguments

Somebody please please help me here
I am new to Unix and wanted to try on using command line arguments.

I am trying to write a program that would monitor a file and print something each time the file changes.

The problem is when I am exeuting the file with
a.out monitored_filename
it doesnt show me anything on the screen. I am not aware of how should I change the monitored_file so that it follows the loop and prints something. I tried to search it in the Unix book , but couldnt find anything.
----------------------------------------------------------------------------


if(fstat(filedes,&stbuf) == -1)
{
printf("couldnt stat \n");
exit(1);
}
for(;
{
if(stbuf.st_mtime != last_time)

printf("file modified");
last_time = stbuf.st_mtime;
sleep(60);
fstat(filedes,&stbuf);
}
}
Reply With Quote
  #2 (permalink)  
Old 08-20-04, 15:06
fla5do fla5do is offline
Registered User
 
Join Date: Oct 2003
Location: Germany
Posts: 138
Hi bubu,
may be this can help you out.

# org_file is your original file you want to monitored

cp org_file help_file

while true
do
LOG_DATE=`date '+%d.%m.%Y %H:%M:%S' `
X=`diff org_file help_file`
if [ -n "$X" ]
then
echo "File was changed at "$LOG_DATE
else
echo "File was not changed "
fi
cp org_file help_file
sleep 60
done
__________________
Greetings from germany
Peter F.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On