Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have the following problem:

I have a file say toto that contains a list of directories like

/data/tt
/data/mm
...

from those directories I want
1) to search for all files in *.w3s
2) sort them by date and owner and get a list of unique owners
3) run finger -m on each owner to get some info about he owner
4) output the result to a file

Can this be done in Awk? or Cshell?

Thanks!
 
This should get you started
You may have to adapt this to your shell :
#!/bin/ksh
>filelist
>finger.txt
for dirs in `cat toto`
do
ls $dirs/*.w3s|cut -c16-23 >> filelist
done
sort -u -ofilelist filelist
for users in `cat filelist`
do
finger -m $users >> finger.txt
done


HTH

Dickie Bird (:)-)))
 
Probably easier in a shell rather than awk,

Code:
#!/bin/bash

# print owner of each w3s file in the list of dirs
for i in `cat toto` ; do
  ls -l $i/*.w3s | awk '{print $3}'
done > users

# produce a unique list
sort -u -o users users

# do finger on each user
for i in `cat users` ; do
  finger -m $i
done > results
 
thanks a lot guys! what about if I only want the users from a specific date say since begining of the year or on a monthly basis?

Thanks!
 
Use the find command

Eg, this one finds all files modified in the last 30 days
Code:
for i in `cat toto` ; do
  find $i -name "*.w3s" -mtime -30 -ls | awk '{print $5}'
done > users

The find command is pretty powerful, so there are lots of options for finding files by various criteria
 
Thanks again. Last thing: when there are no .w3s files in the directories where the search is done I get lines like /directorypath/*.w3s: no such file or directory, how can I get rid of them?
 
> /directorypath/*.w3s: no such file or directory
Mmm, you only get that when you do the 'ls' command, not the 'find' command.

But this is what you would use
ls -l $i/*.w3s 2>/dev/null | awk '{print $3}'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top