[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Linux find command script

Posted on 2006-11-22
7
Medium Priority
?
340 Views
Last Modified: 2010-04-20
I need a script that runs on the /tmp directory that counts the number of files that each user owns, and email that resulting number using mutt.

So, lets say I have 3 users:

user101
user123
user199

User101 has 4 files in the /tmp directory, user123 has 1 file in the /tmp directory, and user199 has 10 files in the /tmp directory.

I want an email created that says:
user101 has 4 files
user123 has 1 file
user199 has 10 files

How can I accomplish this with a script?
0
Comment
Question by:bfilipek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17999508
find /tmp -user user101 -print | wc -l
0
 

Author Comment

by:bfilipek
ID: 17999532
How can I send the result to an email? Also, that only works for one user, I have 200.
0
 
LVL 58

Accepted Solution

by:
amit_g earned 1200 total points
ID: 17999588
ls -l /tmp | awk 'NR != 1 {Count[$3]++} END {for (i in Count) printf("%s has %d files.\n", i, Count[i]);}'
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 84

Expert Comment

by:ozo
ID: 17999597
for user in list_users ; do
  echo $user has `find /tmp -user $user -print | wc -l` files
done | mail
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 800 total points
ID: 18000595
Assuming your users are

user1

to

user200

Then you can do

#!/bin/bash
for i in `seq 1 200`
do
  echo "user$i has `find /tmp -user user$ |wc -l` files"
done | mail -s "Some subject" emailaddr
0
 
LVL 58

Expert Comment

by:amit_g
ID: 18000686
Oh, in case you are looking for a list of user starting with some string like one of your previous question, just add a pipe and grep

ls -l /tmp | grep ' user1' | awk 'NR != 1 {Count[$3]++} END {for (i in Count) printf("%s has %d files.\n", i, Count[i]);}'
0
 

Author Comment

by:bfilipek
ID: 18019324
Thanks to amit_q and Tintin. This is what I ended up using:

ls -l /tmp | awk 'NR != 1 {Count[$3]++} END {for (i in Count) printf("%s has %d files.\n", i, Count[i]);}' | mail -s "Some subject" emailaddr

Works great!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month12 days, 12 hours left to enroll

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question