Log File updated time

hi can any one please help on below .im new to shell scrpting
i need to write a shell script which will check particular log file is presented or not in specific location ,if yes how long it was not modified/not rolling ?if its not modified/log is not rolling script will have to send mail

Can you show us what you have tried so far?

Thanks for the reply..
here is my script:-

fileloc="/given log path lcoation
cd $fileloc
filename=sample.log
if [ -f $filename ]; then
  echo "File Exists"
else
echo "File not exist"

Here is my question to move further:
if file exist script need to check whether log file keep on rolling or not ,if log file not rolling more than 30mins script should trigger mail.
dont know how to write or use if condition in if loop.

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.

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)

#!/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

tx for the reply.
i will check

hi,
when ran the script,its giving the o/p as File not exist even though file exist.

Try execute the script using:

sh -x script.sh

This will make the script its action verbose, so you know what which value has when and how changed.

Did you adapt the variables (fileloc / filename) to your context / situation?

Yes i did.
seems issue with stat command.
error message:

stat:  not found.
newsize=$(stat -c'%Y' "$fullpath")..is not working.
even with newsize=$(stat -c '%s' "$fullpath")

What's your operating system? I've assumed it's Linux, but it's not :confused:

Try to substitute the lines containing the stat commands with

size=$(wc -c < "$fullpath")

and

newsize=$(wc -c < "$fullpath")

respectively.