If you have thousands of email users and you wish to get email alerts of the top 10 largest mail box users from your email without using any other external linux software, here's how to accomplish this task. This task can also be used to check for top largest files of your hard drive from linux terminal command line.
Basically, in order to determine the top or the largest ones, we need to cover first how to sort files by their filesizes. This is the first basic step to determine the largest mail box user or the largest filesize from the rest of the list.
Considering that database is not part of your mail server, consider this approach to determine your largest file from your hard drive or top mail box users on flat file email system.
Sorting Files by FileSizes
By issuing the below command, you get to display sorted files from highest to lowest order
# cd /var/mail
# ls -lS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-rw------- 1 rtolosa mail 899999958 Jan 18 11:41 rtolosa
-rw------- 1 ayusuf mail 899999937 Jan 18 11:41 ayusuf
-rw------- 1 aaluko mail 899999916 Jan 18 11:41 aaluko
-rw------- 1 emarquez mail 899999713 Jan 18 11:41 emarquez
-rw------- 1 aogiri mail 899999617 Jan 18 11:41 aogiri
-rw------- 1 psmith mail 899999599 Jan 18 11:41 psmith
..
<..snipped>
...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alternatively, one quick and dirty approach that would give you the same above result would be
# ls -l | sort -k5 -nr
or
# ls -ls /var/spool/mail/ | du -h /var/spool/mail/* | sort -nr | grep "M"
Now, how can make this data and approach be of useful to our daily tasks. Let us assume we want to get email alerts of these top 5 or top 10 largest file user to our mail box, or how about getting the largest mail spool user on daily basis into our mail box?
Get Email Alerts from Script Outputs
Here's how to get email alerts of top flat mail box users (without database) or top file users?
Simply get the top 5 or top 10 largest file from your system or largest flat mail box user, simply issue the linux head command
Get Top N Largest User
For top 5 largest file or largest mail box user
# cd /var/mail
# ls -l | sort -k5 -nr | head -5
# ls -lS | head -5
Result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-rw------- 1 rtalasa mail 899999958 Jan 18 11:41 rtalasa
-rw------- 1 ayesuf mail 899999937 Jan 18 11:41 ayesuf
-rw------- 1 aaluko mail 899999916 Jan 18 11:41 aaluko
-rw------- 1 amarquez mail 899999713 Jan 18 11:41 amarquez
-rw------- 1 aogiri mail 899999617 Jan 18 11:41 steve
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ls -ls /var/spool/mail/ | du -h /var/spool/mail/* | sort -nr | grep "M" | head -5
Result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
860M /var/spool/mail/yabdulrahman
860M /var/spool/mail/vogobiri
860M /var/spool/mail/rtolosa
860M /var/spool/mail/rlinog
860M /var/spool/mail/raouad
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Of course, the top 10 is similarly like so
# cd /var/mail
# ls -l | sort -k5 -nr | head -10
# ls -lS | head -10
# ls -ls /var/spool/mail/ | du -h /var/spool/mail/* | sort -nr | grep "M" | head -10
Now, a more simplified form of retrieving the largest user from /var/spool/mail, parsing and retrieving only the username and the filesize fields could be done like so
# ls -l | sort -k5 -nr | head -5 | awk '{print $3,$5}'
If you wish to alert yourself and send these results to your email box , simply save the result as file and send the file to your email similarly like so
# ls -l | sort -k5 -nr | head -5 | awk '{print $3,$5}' > top5
# cat top5 | mail -s "My Top Large Files or Users" myown@domain.com
Job Scheduling
Remember the cron scheduling job to do it on regular basis.
Enjoy.
Related Readings:
Cronjob Scheduling Explained
GNOME Task Cron Scheduler
KDE GUI Task Scheduler
Subscription
Categories
- HowTos (612)
- Linux Devices (40)
- Linux Diggs (620)
- Linux News (1541)
- Linux Videos (24)
Recent Posts
Blog Archive
-
▼
2008
(2301)
-
▼
January
(49)
- HowTo: Brasero
- HowTo: ISOs Management for Fedora
- HowTo: Install Nmap with GUI FrontEnd
- HowTo: Create and Manage Genealogy Family Tree via...
- HowTo: Install KFTPGrabber FTP Client
- HowTo: Install FileZilla 3 on Fedora 8
- HowTo: Be Alerted via Popups When Monitoring Log F...
- HowTo: Mount Windows Drive From Linux GUI
- HowTo: Delete Files With 0K Filesize Recursively
- HowTo: Changing Interface's MTU Size
- HowTo: Create Vanishing Virtual Drive
- HowTo: Install Identity.pub Into Remote Machines
- HowTo: Check and Mark Bad Block Of Hard Disk
- HowTo: Install Linux Hardware Browser
- HowTo: Basic RPM Package Queries And Usage
- HowTo: Rebuild Locked Out RPM Database
- HowTo: Display RPM Packages Installed Last Month
- HowTo: Display and List Out All Package Files Rece...
- HowTo: Identify Source Package Name Of A File or F...
- HowTo: Delete Extra Spaces Between Words From Files
- HowTo: Find Hidden Directory Folders Recursively
- HowTo: Create Hidden Directory Folder
- HowTo: Print Only Lines of Text File with N charac...
- HowTo: Sort Files by FileSize and What Else?
- HowTo: Squeezed Out Multiple Lines From Text File
- HowTo: Prevent Binary Execution From Mounted Device
- HowTo: Determine Domain's Expiration Date From Lin...
- HowTo: Create and Overwrite Existing Alias
- HowTo: Get MAC Address of PCs Around
- HowTo: List Out Hidden Files and Hidden Directory ...
- HowTo: Identify Valid Login Shells
- HowTo: Deny User from Logging Into Your System
- HowTo: Remove Tabs From Text Files Completely
- HowTo: Convert Tabs In Each File To Spaces
- HowTo: Install and Say Cheese
- HowTo: Install HomeBank and Manage Personal & ...
- HowTo: Install Mind-Mapping LabyRinth Tool
- HowTo: Install VMWare Server on Fedora 8
- HowTo: Install VMWare Workstation on Fedora 8
- HowTo: Virtual PCLinux 2007 via VirtualBox over Fe...
- HowTo: Enable PortMap on Fedora 8
- HowTo: Linux Hardware Lister Tool - LsHw
- HowTo: Install Bandwidth Shaper - Trickle on Fedora
- HowTo: VnStat Long-Term Traffic Monitoring via CLI
- HowTo: Install NetSpeed Traffic Monitoring Applet
- HowTo: Install IPTraff LAN Monitoring Tool
- HowTo: Install Ibmonitor Interface Bandwidth Monitor
- HowTo: Install IfTop Bandwidth Monitoring Tool
- HowTo: Fedora WordPress Installation
-
▼
January
(49)
Friday, January 18, 2008
HowTo: Sort Files by FileSize and What Else?
Subscribe to:
Post Comments (Atom)
ILoveTux - howtos and news | About | Contact | TOS | Policy
0 comments:
Post a Comment