LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-26-2007, 12:40 AM   #1
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Rep: Reputation: 30
Script error


Hi,

I had wrote a script to monitor my server load and to send me a mail on high loads. But i am unable to execute it , as i get the following error.

bash scriptfile
(standard_in) 1: parse error

The file is as below:

#!/bin/bash
ALERT=1
EMAIL="myname@company.com"
SUB="Alert $(hostname) load average"
TEXT="Load Average:"
A=1

L5M="$(uptime | awk -F "$TEXT" '{ print $2 }' | cut -d, -f1)"
L10M="$(uptime | awk -F "$TEXT" '{ print $2 }' | cut -d, -f2)"
L15M="$(uptime | awk -F "$TEXT" '{ print $2 }' | cut -d, -f3)"

TEMPFILE="$(mktemp)"
echo "Load average Crossed allowed limit $ALERT" >> $TEMPFILE
echo "Hostname: $(hostname)" >> $TEMPFILE
echo "Local Date & Time : $(date)" >> $TEMPFILE

OUTPUT=$(echo "$L15M > $ALERT" | bc)

if ["$OUTPUT" -eq "$A" ];
then
echo ok
mail -s "$SUB" "$EMAIL " <$TEMPFILE
fi


rm -f $TEMPFILE


Please point out the errors in my script file.


Thanks in Advance
 
Old 12-26-2007, 01:08 AM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Code:
if ["$OUTPUT" -eq "$A" ];
That line is giving an error. There should be a space after '['

Code:
if [ "$OUTPUT" -eq "$A" ];
Also the output of uptime on my system uses 'load average:' (lowercase l and a) not 'Load Average:' so that might be a problem. TEXT="load average:"

P.S. Code is easier to read and better formatted with code tags.

Last edited by dive; 12-26-2007 at 01:23 AM.
 
Old 12-26-2007, 01:34 AM   #3
ZAMO
Member
 
Registered: Mar 2007
Distribution: Redhat &CentOS
Posts: 598

Original Poster
Rep: Reputation: 30
Thank you.

It works
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Script error "line 31: syntax error: unexpected end of file" eswanepoel General 7 12-07-2007 09:28 AM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 07:05 PM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 10:01 AM
linux 9 and java script error - premature end of script header sibil Linux - Newbie 0 01-06-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration