The UNIX and Linux Forums  

Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > Hardware > Filesystems, Disks and Memory
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-18-2006
hegemaro hegemaro is offline
Registered User
  
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 134
Using a simple pipeline you can get the current size of a file. Wrapping that in a script and setting a threshold would allow you to trap a file size. The following examples were executed in ksh on a Solaris 8 system but should be sufficiently generic:

Code:
$ ls -l /var/log/syslog 
-rw-r--r--   1 root     root        4109 May 18 07:30 /var/log/syslog
$ ls -l /var/log/syslog | tr -s " " "\t" | cut -f5
4109
Save that as a variable and compare:
Code:
FILESIZE=$(ls -l /var/log/syslog | tr -s " " "\t" | cut -f5)

if [ $FILESIZE -lt 10000 ]
then
    :   # no action required
else
    echo "$FILESIZE" | mailx -s "file limit reached" root
fi
And as my grandmother always said, "season to your taste." I hope this helps.

Last edited by hegemaro; 05-20-2006 at 07:36 AM..