Solved

Linux find command script

Posted on 2006-11-22
7
327 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
  • 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 300 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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 200 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

770 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