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