Trying to look at the contents of two files 
Author Message
 Trying to look at the contents of two files

Hi there,

I manage some HP systems and I was trying to add some passwd aging
without having to use HP-UX Trusted S/W. I don't want to use Perl
because I have to install it on all systems.

I use awk to get the user names from the passwd file. I also use awk to
get a filtered output from the "last" command. The filtered output from
last only displays user name and last log-in date.

I thought I could load the contents of the stripped down passwd file
into an array, then compare against the contents of the stripped down
last command and figure out who has not logged-in in more that 90 days.

Unfortunately this has proved to be far more complicated that I thought.

I know I'm asking a very broad question but I have run out of ideas.
Does anybody have any other ideas on how to do this, perhaps using awk.

Thanks,

Carlos Ramirez



Sun, 01 May 2005 04:56:21 GMT  
 Trying to look at the contents of two files

Quote:
> Hi there,

> I manage some HP systems and I was trying to add some passwd aging
> without having to use HP-UX Trusted S/W. I don't want to use Perl
> because I have to install it on all systems.

> I use awk to get the user names from the passwd file. I also use awk
to
> get a filtered output from the "last" command. The filtered output
from
> last only displays user name and last log-in date.

> I thought I could load the contents of the stripped down passwd file
> into an array, then compare against the contents of the stripped down
> last command and figure out who has not logged-in in more that 90
days.

> Unfortunately this has proved to be far more complicated that I
thought.

> I know I'm asking a very broad question but I have run out of ideas.
> Does anybody have any other ideas on how to do this, perhaps using
awk.

> Thanks,

> Carlos Ramirez

Try this, using gawk:

$ cat last.dat
i       30/06/2002
you     29/09/2002
me      11/11/1965
him     01/01/2002
her     02/02/2002
admin   13/11/2002
them    01/01/2000
others  01/01/2000
all     01/01/2000
else    01/01/2000

$ cat pass.dat
i
me
you
him
her
admin
them
others
all
else

$ cat carlos.awk
# process pass.dat vs last.dat
FILENAME == ARGV[1] {last[$1] = $2; next}
FILENAME == ARGV[2] {pass[$1]}
END {
  now = systime()
  for (i in pass) {
    split(last[i],d,"/")
    d[4] = d[5] = d[6] = "00"
    if ((now - mktime(d[3]" "d[2]" "d[1]" "d[4]" "d[5]" "d[6])) > 90 *
86400) {
      print i, "has not logged on for 90 days"
    }
  }

Quote:
}

$ gawk -f carlos.awk last.dat pass.dat | sort
all has not logged on for 90 days
else has not logged on for 90 days
her has not logged on for 90 days
him has not logged on for 90 days
i has not logged on for 90 days
me has not logged on for 90 days
others has not logged on for 90 days
them has not logged on for 90 days

$

NB relies on gawk's mktime() and systime() functions.  I assumed that
your "last" file didn't include the time, but if it does adjust the code
to cope.

HTH
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"



Sun, 01 May 2005 11:24:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. input two files, aggregate the contents of selected data

2. Merging contents of two files

3. HELP: Trying to combined two files (not append)

4. read two sets of data from two spread sheet files to two arrays problem

5. Writing two equal files without creating two files in dct

6. try gfdg try kuiou try gsdfas try

7. Debugger Question: (V55ee) Trying to Edit String Variable Contents

8. How to exchange the contents of two variables

9. how to compare two columns in two files?

10. Two files, two linking keys

11. searching one file using the contents of another file

12. Looking for Table widget for displaying Database contents

 

 
Powered by phpBB® Forum Software