LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 06-27-2007, 01:57 PM   #1
kaplan71
Member
 
Registered: Nov 2003
Posts: 718

Rep: Reputation: 39
Need help debugging a script I wrote


Hi there --

I am trying to debug a script that I wrote to monitor disk usage on one of our servers with an automatic notification to those who exceed the limit. Here is the text of the script:

#!/bin/bash

# find disk hogs

users='ls -1 /home'
limit=100000

for user in $users
do
diskuse='du -hcs /home/$user | awk '{ print $1 }' -'
if [ $diskuse -gt $limit ]
then
/bin/mail $user <<!

Dear $user,

It is expected that users on this system keep their disk usage below $limit. You are currently using $diskuse. Please delete any unnecessary files and directories from your home directory.

I can help you archive old files and directories if you wish. Please let me know if there are any that can be archived to tape, and I will be happy to do the necessary backups. If you have any questions, please feel free to contact me at 617-724-6949.

Thank-you for your time and patience on this matter.

!
fi
done

When I tried to run the script, the following errors repeatedly appeared onscreen:

line 10: print: command not found
line 11: [: -gt: unary operator expected

The operating system is Fedora Core 5. Does anyone have any insight to this? Thanks.
 
Old 06-27-2007, 02:01 PM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
Try
diskuse=$(du -s /home/$user | awk '{ print $1 }')

Edit: dropped the -h because of the comparison you do afterwards

Last edited by uselpa; 06-27-2007 at 02:06 PM.
 
Old 06-27-2007, 02:06 PM   #3
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
Nnnnnever mind. uselpa beat me to it!

Last edited by wjevans_7d1@yahoo.co; 06-27-2007 at 02:08 PM.
 
Old 06-27-2007, 02:10 PM   #4
kaplan71
Member
 
Registered: Nov 2003
Posts: 718

Original Poster
Rep: Reputation: 39
I made the change that you suggested, and the error messages I am now getting are the following:

du: cannot access '/home/ls' : no such file or directory
line 11: [: -gt:unary operator expected
du: cannot access '/home/-1' : no such file or directory
line 11: [: -gt:unary operator expected
du: cannot access '/home/home' : no such file or directory
line 11: [: -gt:unary operator expected
 
Old 06-27-2007, 02:17 PM   #5
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
users=$(ls -1 /home)
 
Old 06-27-2007, 02:24 PM   #6
kaplan71
Member
 
Registered: Nov 2003
Posts: 718

Original Poster
Rep: Reputation: 39
That seems to have fixed it. One question: if I want the limit mentioned in the e-mail
that is sent out to read megabytes, can I simply change the limit= line from:

limit=80000

to

limit=80MB

Thanks.
 
Old 06-27-2007, 02:28 PM   #7
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 46
no, because the comparison wouldn't work
if you know it's MB then divide the amount by 1024*1024 or something along those lines
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Just a little backup script I wrote which does what I want it to pwc101 LinuxQuestions.org Member Success Stories 5 09-29-2006 08:11 AM
Shell script debugging rbautch Programming 11 07-20-2006 10:33 PM
Debugging a Bash Shell Script solarblast Linux - General 1 02-23-2006 01:44 AM
debugging configure script Avatar33 Programming 3 03-23-2005 04:35 PM
not that anyone cares but... here's a free decompression script i wrote versaulis Linux - Software 8 11-23-2003 02:21 PM


All times are GMT -5. The time now is 01:08 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration