Sponsored Content
Full Discussion: Log File updated time
Top Forums Shell Programming and Scripting Log File updated time Post 302926380 by junior-helper on Sunday 23rd of November 2014 10:30:31 PM
Old 11-23-2014
Quote:
rolling or not
If you mean stuff gets appended to the file or not, then you should try below code. It works by reading the file size, sleeping 30 min, reading the file size again and comparing the two values.

Quote:
not modified
It's also quite possible that the content of a file is changed, but the file size remains the same.
Obviously, in this case you cannot rely on the file size and should compare the modification times.
The code below can be easily adapted to do so.
Hint: You use the %Y format sequence in the stat command instead of %s (Check man stat or stat --help for details)
Code:
#!/bin/bash

fileloc="/tmp"
filename="test.txt"
fullpath="$fileloc"/"$filename"
interval=1800 # seconds (30 minutes)

if [ -f "$fullpath" ]; then
 echo "File Exists"
 size=$(stat -c'%s' "$fullpath")

 # infinite loop
  while true; do
   sleep $interval
   newsize=$(stat -c'%s' "$fullpath")
    if [ $size -ne $newsize ]; then

     echo "Sending mail."
      printf "Size of %s changed.
Size 30 minutes ago: %d bytes.
Current size: %d bytes." "$fullpath" "$size" "$newsize" |\
      mailx -s "Size changed!" someone@example.net

     size=$newsize
    fi
  done

else
  echo "File not exist"
fi

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Diff b/w modification & updated time

Hi All, What is the difference b/w last modification time and last updated time. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

2. UNIX for Dummies Questions & Answers

Showing Last Updated Time

Hi, I've got a question. How do I show the last updated time? Whenever I do any of the following: ls -l ls -lu ls -lt I get the creation time. I need the modification/last update time. I'm FTP'ing a file to a different server. I'd like to know when the FTP is completed. (2 Replies)
Discussion started by: redge
2 Replies

3. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

4. 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

5. Shell Programming and Scripting

Old time stamp being updated for new files

Hello Friends I am facing a weird problem :confused:, we receive thousands of files in my system on a daily basis, access time stamp on some of the files are being updated as old time stamp like 1968-01-19, Could some one help me what could be causing this? so that i can narrow down the problem... (4 Replies)
Discussion started by: Prateek007
4 Replies

6. Shell Programming and Scripting

How to find last updated date and time of a folder in Perl?

Hi All, I have a process which after some time continues move a files to some folder(say the name of the folder is logdir) What i am trying to do is as the files are coming to the logdir folder, I want the latest updated time and date of the folder in PERL. (1 Reply)
Discussion started by: parthmittal2007
1 Replies

7. Shell Programming and Scripting

Log search and mail it if the log is updated before 24 hours from the current time

Hi , We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below 1) We use only TAIL -100 <location and name of the log> Command to check the logs. 2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies

8. 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

9. Shell Programming and Scripting

How to find the any log which is not updated since particular date?

Hello, Iam running with one issue, since particular date looks like one of the script vanished from the system after restarting of the system. I dont know which scrit it was but definatelt there should be one. but might be some logs would be there which have not updated from that day. so... (2 Replies)
Discussion started by: ajju
2 Replies

10. Shell Programming and Scripting

Grep a log file starting from a specific time to the end of file

I have a log file which have a date and time at the start of every line. I need to search the log file starting from a specific time to the end of file. For example: Starting point: July 29 2018 21:00:00 End point : end of file My concern is what if the pattern of `July 29 2018 21:00:00`... (3 Replies)
Discussion started by: erin00
3 Replies
FILESIZE(3)								 1							       FILESIZE(3)

filesize - Gets file size

SYNOPSIS
int filesize (string $filename) DESCRIPTION
Gets the size for the given file. PARAMETERS
o $filename - Path to the file. RETURN VALUES
Returns the size of the file in bytes, or FALSE (and generates an error of level E_WARNING) in case of an error. Note Because PHP's integer type is signed and many platforms use 32bit integers, some filesystem functions may return unexpected results for files which are larger than 2GB. EXAMPLES
Example #1 filesize(3) example <?php // outputs e.g. somefile.txt: 1024 bytes $filename = 'somefile.txt'; echo $filename . ': ' . filesize($filename) . ' bytes'; ?> ERRORS
/EXCEPTIONS Upon failure, an E_WARNING is emitted. NOTES
Note The results of this function are cached. See clearstatcache(3) for more details. Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to "Supported Protocols and Wrappers" to determine which wrappers support stat(3) family of functionality. SEE ALSO
file_exists(3). PHP Documentation Group FILESIZE(3)
All times are GMT -4. The time now is 06:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy