Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    1

    Unanswered: 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);
    }
    }

  2. #2
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •