in reply to Standardized Template
Here is an example of what I mean, which may or may not be what you are after.
I am trying to avoid using modules due to a number of reasons. The two biggest reasons is that my employer has made it a requirement and I need to be able to explain the code line by line. I do not mind "borrowing" ideas from modules, but ultimately the code needs to be my own.
So the type information I need to get out of my program is as follows:
So basically, I need to compare every field against every other field as well as make provisions for the possibility the field won't exist at all on certain servers. My first hurdle is that the encrypted password is not stored in /etc/passwd but in /etc/shadow. I am using shadow.hostname syntax for that.
Here is what I have come up with so far:
Additionally, any help or insight would be appreciated. I am rather new to Perl so I understand this might not be the best approach. If you do choose to suggest an alternative approach, keep in mind my requirements I stated above#!/usr/bin/perl -w use strict; my @hosts = qw(zeus mercury athena); my (@p_files, @s_files); my %data; for my $host ( @hosts ) { push @p_files , 'passwd.' . $host; push @s_files , 'shadow.' . $host; } # Process /etc/passwd files FILE: for my $file ( @p_files ) { if ( ! open (PASSWD, $file) ) { warn "Unable to open $file : $!"; next FILE; } LINE: while ( <PASSWD> ) { my @fields = split /:/; if ( @fields != 7 ) { warn "$_ in file $file is corrupt"; next LINE; } $data{$fields[0]}->{$file} = \@fields; } } # Process /etc/shadow files FILE: for my $file ( @s_files ) { if ( ! open (SHADOW, $file) ) { warn "Unable to open $file : $!"; next FILE; } LINE: while ( <SHADOW> ) { # Not sure what to do here # but I know I need to modify # $data{account}->{$file}[1] } } # Need code help here to do all the comparisons I need
I can guarantee tux242 that if you word take the time to pose a question like this you will be much more likely to get answers that you are seeking.
Cheers - L~R
|
|---|