LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-08-2012, 01:16 AM   #1
SeerKan
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
Help with a small bash script


Hey guys,

I want to mention that I'm still a beginner at this so bear with me

I made a small script that will check the users and if the size is larger than, let's say 204800, it will print the user and then send an email with the report.

Everything works except the fact that the script prints all the users, not only the one's having the value larger than 204800

This is the script, any suggestions are welcome:

Code:
#! /bin/bash
#finding all users, checking folder size and sorting

/usr/bin/find /home -printf "%u %s\n" | /usr/bin/awk '{user[$1]+=$2}; END { if (user[i] -gt 204800) for( i in user) print i " " user[i]}' | /bin/sort -rn +1 -2 > /root/disk-usage.txt;
#cheking if there is something in disk-usage.txt
if ls /root/ | grep -q "disk-usage.txt"
then
    # send email containing the output of the file
   /bin/cat /root/disk-usage.txt | mail -s "Disk Usage Report" my@email.com

fi;

#delete txt file
rm -rf /root/disk-usage.txt
 
Old 12-08-2012, 05:31 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
It is probably easier to just use

Code:
du -s /home/* | awk '{if($1 > 204800){print $0;}}' | sort -rn > /root/disk-usage.txt
'du' does all the counting for you, and then do the comparison. I think your awk might work if you put braces ("{" and "}") in it (currently, if you check the contents of /root/disk-usage.txt, then you can see it contains all users' usage, not the ones who have used too much), but it's probably simpler to use 'du' and then a smaller, clearer, awk command.

Hope this helps,
 
Old 12-08-2012, 05:49 AM   #3
SeerKan
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
That helped, thanks.
 
  


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
[SOLVED] small bash script m3phisto Linux - Newbie 7 04-26-2011 04:38 AM
Very small bash script enemorales Programming 8 02-25-2005 02:47 AM
small bash script issue zoomzoom Linux - General 7 06-08-2004 06:33 PM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM
sed in small BASH script OhLordy Linux - General 1 08-29-2003 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:14 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