trying to check if the file is getting updated or not


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting trying to check if the file is getting updated or not
# 1  
Old 08-26-2010
trying to check if the file is getting updated or not

#!/bin/sh
#set -x
Current_Date=`date +"%b %e"`
Filepmdate=`ls -ltr /file/ | tail -5 | awk '{print $6,$7}'`
if [ "$Current_Date" = "$i" ] ; then
echo " "
exit 0
else
echo "Log files are not updated please check"
exit 0
fi
done

> sh -x l12.sh
+ + date +%b %e
Current_Date=Aug 26
+ + ls -ltr /file/
+ awk {print $6,$7}
+ tail -5
Filepmdate=Aug 26
Aug 26
Aug 26
Aug 26
Aug 26
+ [ Aug 26 = ]
+ echo Log files are not updated please check
Log files are not updated please check
+ exit 0

how do i compare four dates to one date here.is this completely wrong .please help and thanks in advance
# 2  
Old 08-26-2010
Code:
ls -ltr /file/

will list all files under the folder /file, tail -5 will list the last 5 files, that's why you get five "Aug 26".

---------- Post updated at 03:49 PM ---------- Previous update was at 03:44 PM ----------

not tested, just follow your idea and update it.

Code:
Current_Date=`date +"%b %e"`

ls -ltr /file/ | tail -5 | awk '{print $6,$7}' | while read i
do
  if [[ "$Current_Date" == "$i" ]] ; then
     echo " "
     exit 0
  else
     echo "Log files are not updated please check"
     exit 0
  fi
done


Last edited by rdcwayx; 08-26-2010 at 03:42 AM..
# 3  
Old 08-26-2010
yes its the last five files.thanks you for ure response

---------- Post updated at 01:36 AM ---------- Previous update was at 01:15 AM ----------

+ + date +%b %e
Current_Date=Aug 26
+ + ls -ltr /file/
+ awk {print $6,$7}
+ tail -5
log1.sh[11]: Aug 26^JAug 26^JAug 26^JAug 26^JAug 26: cannot open
getting this how do we get the timestamp also even $8
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Redhat check when package was updated

Is there a way to check when a package was updated on your redhat system? (2 Replies)
Discussion started by: cokedude
2 Replies

2. UNIX and Linux Applications

Firefox updated when Never Check for updates selected

Can anyone explain how Firefox updated when Never Check for updates is selected? (4 Replies)
Discussion started by: cokedude
4 Replies

3. UNIX for Advanced & Expert Users

AIX idea needed to check the logs updated date and time

Hi with the help of Gabriel canepa, i have just edited filename only in his code. The help which i got and he helped is 1) I have around 22 logs and each log should be updated in the last 24 hours from the current timestamp. 2) It should check for ERROR message (not error,Error) in the log and... (2 Replies)
Discussion started by: Kalaihari
2 Replies

4. Shell Programming and Scripting

Is there any command to know what updated last in file?

Is there any command to know what updated last in file? (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

5. Shell Programming and Scripting

Script to wait until file is updated

Hello, I need to evaluate (under BASH) if the certain file has been updated or not. If the file still wasn't updated, script should wait. The script picks up the time stamp of the file using command OldTimestamp=$(date -r $MyDir/$MyFile), but I don't know how to code a waiting loop with new and... (6 Replies)
Discussion started by: sameucho
6 Replies

6. Shell Programming and Scripting

If File has been updated, do something??

Put this together from somewhere else on the forums, just modified it and added the loop. #!/bin/ksh localFile=$1 remoteFile=$2 #source FTP parameters . .ftp_put.cfg mylog=ftp_session.log echo "$(date "+%H:%M:%S") - Attempt to FTP $1 to $2" > $mylog machine="server1 server2... (5 Replies)
Discussion started by: cbo0485
5 Replies

7. Programming

Log file not getting updated

hi all, i'm a student and managing lab at my insti. there in one application in which log file has to be maintaine the number of bytes transferred and received. but after certain entries these two attributes stop getting updated and holds same values for rest of the session. This happens one time... (4 Replies)
Discussion started by: KornFire
4 Replies

8. UNIX for Dummies Questions & Answers

Find last updated file

Hi all, my problem is teh following: I need to move a file from a folder to another and I usually do it by the get command but in this case I have a list of file in the source folder and I have to select only the lust updated one. Ho to do this? All the files have the same name followed... (4 Replies)
Discussion started by: callimaco0082
4 Replies

9. Shell Programming and Scripting

checking out latest updated file

hi, i was wondering if there is a way to find out which file is updated the most recent time in the entire file system.... most probably this would be refering to some LOG file, but i wanna find a way which file was that... some script should work or what? can anybody help me out on that. for... (3 Replies)
Discussion started by: asadlone
3 Replies

10. Shell Programming and Scripting

Creating an updated file

Hi, I would like to define a script in order to update a file with the last updated records: I wrote : #!/bin/sh YEAR=$(date +%Y) MONTH=$(date +%m) DAY=$(date +%d) COMM=/usr/bin/comm for file in * ; do if ] ; then FILE=${DPSTY} UNIQUE=Unique_${FILE} ... (4 Replies)
Discussion started by: dbfree
4 Replies
Login or Register to Ask a Question