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 > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 06-04-2008
altamaha altamaha is offline
Registered User
  
 

Join Date: Feb 2008
Location: Georgia
Posts: 23
Question Running a script with cron

I have the following script (trapsize) that checks a file size on my syslog server, and if the file is gt 6g, it will mail an alert to the admin for inspection. The following works like a champ when I execute ./trapsize logged in as root user using bash shell.

Code:
FILESIZE=$(ls -l /opt2/fwsm/fwsm | tr -s " " "\t" | cut -f5)
MAILGROUP="userA@conus.army.mil, userB@conus.army.mil, userC@conus.army.mil"

if [ $FILESIZE -lt 6000000000 ]
then
    :  # no action required
else
    echo "$FILESIZE" | mailx -r userD@post.army.mil -s "File Size Limit of 6g Reached on fwsm" $MAILGROUP
fi
I need to have the script in /usr/lib with root:bin ownership and permissions set so that cron can run the script at various times during the day.

I have created the following in /usr/lib/trapsize for cron, but I can't get it to function. Any advice would be appreciated.

Code:
#! /bin/sh
#
# Script will periodically check the log size for the FWSM and notify admin if greater than 6g - jbrannen
#
#
#

FILE=fwsm
FILEPATH=/opt2/fwsm/
FILESIZE=$(ls -l $FILEPATH$FILE | tr -s " " "\t" | cut -f5)
MAILGROUP="userA@conus.army.mil, userB@conus.army.mil, userC@conus.army.mil"


if [ $FILESIZE -lt 6000000000 ]
then
    :  # no action required
else
    echo "$FILESIZE" | mailx -r userD@post.army.mil -s " File Size Limit of 6g reached on fwsm" $MAILGROUP
    rm $FILESIZE
fi
The error is as follows;
trapsize: syntax error at line 10: `FILESIZE=$' unexpected