Find the answer to your Linux question:
Results 1 to 7 of 7
hi! i would like to create a bash script to know if some Log's are modified today. Normaly i go to the prompt and put: ls -lha /var/log/cpu.log ls -lha ...
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48

    check if file is modified today

    hi!
    i would like to create a bash script to know if some Log's are modified today.
    Normaly i go to the prompt and put:

    ls -lha /var/log/cpu.log
    ls -lha /var/log/mem.log
    ls -lha /var/log/disk.log

    Is it possible to create a script to make a simple exit?
    For example:

    CPU = OK
    MEM = OK
    DISK = OK


    thanks!

  2. #2
    Just Joined!
    Join Date
    Aug 2005
    Posts
    65
    do this work ?

    Code:
    #!/bin/bash
    
    DIR=/var/log/
    FILE1=cpu.log
    FILE2=mem.log
    FILE3=disk.log
    
    if [[ -z $(find $DIR -atime -1 -name $FILE1) ]];
    then
    	echo "$FILE1 is ok "
    fi
    
    if [[ -z $(find $DIR -atime -1 -name $FILE2) ]];
    then
    	echo "$FILE2 is ok "
    fi
    
    if [[ -z $(find $DIR -atime -1 -name $FILE3) ]];
    then
    	echo "$FILE3 is ok "
    fi

  3. #3
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    it returns:

    cpu.log [ FAIL ]
    mem.log [ OK ]

    files:

    -rwxrwxrwx 1 tomcat oper 4.5M Nov 19 13:00 /var/log/cpu.log.log
    -rwxrwxrwx 1 tomcat oper 1.1M Nov 19 13:00 /var/log/mem.log.log


    why??? In two cases the date is today....

  4. #4
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    That is because you want to use the modification time (mtime) instead of the access time (atime).

  5. #5
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    whats the different between mtime and atime?
    If I put atime the result is: OK and FAIL
    and if i put mtime the result is: FAIL and FAIL.

    why???

  6. #6
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    Quote Originally Posted by guif View Post
    whats the different between mtime and atime?
    Look it up on google.

    If I put atime the result is: OK and FAIL
    and if i put mtime the result is: FAIL and FAIL.

    why???
    Are you using the above script? If so, this is what it does: it uses the "find" program to look for files in your directory that were accessed less than one day ago and have a particular name. It then checks whether find printed anything (i.e. found such a file) and prints "OK" if it did not.

    I suggest the following alternative:

    Code:
    touch -d 2008-11-19 midnight
    for file in /var/log/{cpu,mem,disk}.log
      do if [[ $file -nt midnight ]]
        then echo $file
      fi
    done

  7. #7
    Just Joined!
    Join Date
    Oct 2008
    Posts
    48
    thanks! I ckeck it!

Posting Permissions

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