bfilipek
asked on
Linux find command script
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?
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?
find /tmp -user user101 -print | wc -l
ASKER
How can I send the result to an email? Also, that only works for one user, I have 200.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
for user in list_users ; do
echo $user has `find /tmp -user $user -print | wc -l` files
done | mail
echo $user has `find /tmp -user $user -print | wc -l` files
done | mail
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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]);}'
ls -l /tmp | grep ' user1' | awk 'NR != 1 {Count[$3]++} END {for (i in Count) printf("%s has %d files.\n", i, Count[i]);}'
ASKER
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!
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!