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 10-17-2007, 04:33 AM   #1
Zombie13
Member
 
Registered: Nov 2003
Posts: 70

Rep: Reputation: 15
Need help with a script.


I found the following script... http://linuxgazette.net/issue13/slew.html

It appears to be exactly what I'm looking for, but it fails with "./slew.sh: line 33: syntax error: unexpected end of file". I'm running the script by doing "./shew.sh 90".

Can anyone shed some light on this?

Code:
#! /bin/bash
        ## SLEW: Space Low Early Warning
        ##      by James T. Dennis,
        ##      Starshine Technical Services
        ##
        ## Warns if any filesystem in df's output
        ## is over a certain percentage full --
        ## mails a short report -- listing just
        ## "full" filesystem.
        ## Additions can be made to specify
        ## *which* host is affected for
        ## admins that manage multiple hosts

adminmail="root"
        ## who to mail the report to


threshold=${1:?"Specify a numeric argument"}
        ## a percentage -- *just the digits*

# first catch the output in a variable
fsstat=`/bin/df`

echo "$fsstat" \
        | gawk '$5 + 0 > '$threshold' {exit 1}'  \
   || echo "$fsstat" \
        | { echo -e "\n\n\t Warning: some of your" \
                "filesystems are almost full \n\n" ;
                gawk  '$5 + 0 > '${threshold}' + 0 { print $NF, $5, $4 }' } \
        | /bin/mail -s "SLEW Alert" $adminmail

exit
Cheers!
 
Old 10-17-2007, 07:31 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
The only error I see is the shebang line: #! /bin/bash. Remove the space so that it looks like this: #!/bin/bash.
 
Old 10-17-2007, 09:42 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

I haven't actually checked it, but I do believe that the OR statement ( {exit 1}'\|| echo "$fsstat" ) is causing the problem.

I don't think it's implemented the way it should, I'm going to take a good look when I'm home and maybe come up with an alternative.

Anyway, hope this helps.
 
Old 10-17-2007, 01:14 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi again,

I took another look at the script and found out that the part between the curly braces are the problem (and not the OR part as mentioned earlier). The problem is that I cannot get the script to work the way the author intended it to work......

I do have an alternative based on what the above script does:
Code:
#!/bin/bash

# who to mail the report to
adminMail="root"

# a percentage -- *just the digits*
threshold=${1:?"Specify a numeric argument"}

# store output
output=$(/bin/df | \
gawk -v threshold=$threshold '
$5 + 0 >= threshold { print $NF, $5, $4 }
')

# if output is filled, it needs to be reported/mailed
if [[ -n $output ]]
then
/usr/bin/mail -s "Filesystem Alert" $adminMail << TOEND
"Warning: some of your filesystems are almost full:"
$output
TOEND
fi

exit 0
You need to check if the mail program resides in /bin or /usr/bin and change that line in the script accordingly.

Hope this helps.
 
Old 10-17-2007, 01:31 PM   #5
Zombie13
Member
 
Registered: Nov 2003
Posts: 70

Original Poster
Rep: Reputation: 15
Thank you very much for the replies! And a very big thank you for taking the time to write the script!

Unfortunately, though... I run the script and just get dropped back to a prompt. I have 8 filesystems which should be reported as over the 90% threshold, but there is nothing output to the terminal or console, and nothing to root's mail.

I did have to change the entry for the mail program to "/bin/mail", as you anticipated.

Many thanks for your help with this. Our web server at work was set up badly by a third party, and I would like to be alerted before the impending problem of the server filling (they have everything under the / filesystem!)

Cheers!
 
Old 10-17-2007, 01:42 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Strange it doesn't work, I did test it on my side and it worked fine.

Ok, what happens if you replace this:

/usr/bin/mail -s "Filesystem Alert" $adminMail << TOEND
"Warning: some of your filesystems are almost full:"
$output
TOEND

To:

echo $output

If that doesn't show anything, you can safely assume that it is not a mail problem. If it does give some output, the mail part is the problem.

Another thing, I assume that all output of the df command is the same, but just to be sure this is what I get when running df (just a few relevant lines):

Code:
 $ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda3             66055932  14327388  48373104  23% /
/dev/sda4            364794160 100748640 245515012  30% /data
/dev/sdb3             11820088    160524  11059136   2% /tmp
The bold parts (field 5) is what we are interested in.
 
Old 10-17-2007, 02:11 PM   #7
Zombie13
Member
 
Registered: Nov 2003
Posts: 70

Original Poster
Rep: Reputation: 15
Ah, that did give the output I need. Looks like a mail problem then! Although I'm testing this on my home PC, not the server at work. I'm happy that mail is working fine on the server, as I've set it to e-mail me the backup reports each morning which works fine.

Many thanks!
 
  


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
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
i get an error message running php script inside a cgi script. repolona Linux - Software 0 02-22-2007 09:10 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 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 02:34 PM.

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