Solved

Linux find command script

Posted on 2006-11-22
7
324 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now