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 ...
- 11-19-2008 #1Just 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!
- 11-19-2008 #2Just 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
- 11-19-2008 #3Just 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....
- 11-19-2008 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
That is because you want to use the modification time (mtime) instead of the access time (atime).
- 11-19-2008 #5Just 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???
- 11-19-2008 #6Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
Look it up on google.
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.If I put atime the result is: OK and FAIL
and if i put mtime the result is: FAIL and FAIL.
why???
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
- 11-20-2008 #7Just Joined!
- Join Date
- Oct 2008
- Posts
- 48
thanks! I ckeck it!


Reply With Quote
