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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
running script in cron - with ssh commands - not working frustrated1 Shell Programming and Scripting 31 09-16-2008 10:14 AM
error in running shell script in cron sari Shell Programming and Scripting 3 04-16-2008 04:09 AM
Running a script in cron question NycUnxer UNIX for Dummies Questions & Answers 3 01-02-2008 01:22 PM
Running a Cron Script only @ Startup Pls Help!! perk_bud Shell Programming and Scripting 3 07-17-2007 06:29 AM
Running script using cron ankurgupta Shell Programming and Scripting 4 12-12-2002 10:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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
  #2 (permalink)  
Old 06-04-2008
in2nix4life's Avatar
in2nix4life in2nix4life is offline
Registered User
  
 

Join Date: Oct 2007
Location: East Coast
Posts: 58
You have a space between FILESIZE=$ ( .

Try changing it to FILESIZE=$( .

Hope this helps.
  #3 (permalink)  
Old 06-05-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Or your /bin/sh is too old to understand the $(ls ...) syntax. Maybe try with FILESIZE=`ls ...` instead.
  #4 (permalink)  
Old 06-05-2008
altamaha altamaha is offline
Registered User
  
 

Join Date: Feb 2008
Location: Georgia
Posts: 23
Thumbs up

Thanks. The solution was to use the back tics instead of the $( as suggested. The extra space in the example was an illusion produced by the font I guess, because it was not in the actual code.

I do appreciate the help.
JB
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0