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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-27-2007, 01:57 PM
|
#1
|
|
Member
Registered: Nov 2003
Posts: 703
Rep:
|
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.
|
|
|
|
06-27-2007, 02:01 PM
|
#2
|
|
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507
Rep:
|
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.
|
|
|
|
06-27-2007, 02:06 PM
|
#3
|
|
Member
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938
Rep:
|
Nnnnnever mind. uselpa beat me to it!
Last edited by wjevans_7d1@yahoo.co; 06-27-2007 at 02:08 PM.
|
|
|
|
06-27-2007, 02:10 PM
|
#4
|
|
Member
Registered: Nov 2003
Posts: 703
Original Poster
Rep:
|
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
|
|
|
|
06-27-2007, 02:17 PM
|
#5
|
|
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507
Rep:
|
users=$(ls -1 /home)
|
|
|
|
06-27-2007, 02:24 PM
|
#6
|
|
Member
Registered: Nov 2003
Posts: 703
Original Poster
Rep:
|
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.
|
|
|
|
06-27-2007, 02:28 PM
|
#7
|
|
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507
Rep:
|
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
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:19 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|