[clue-tech] Script Help
marcus hall
marcus at tuells.org
Tue May 10 19:02:17 MDT 2005
On Tue, May 10, 2005 at 04:53:53PM -0600, Ballon, Mike wrote:
> I wrote a tiny script for parse some output from an Exchange 2003 widget,
> the input file contains data like what you see below. Now on the first two
> lines you'll notice the input is "constant" but on the third the user is
> under a sub ou and I just can't figure out how to compensate for the
> variable position of the second important field. In the first two lines the
> position of the field I want is 4th, on the 3rd line it's 5th. What the
> Exchange widge is suppose to show mailboxes that do not have a 1-1
> relationship so I need an output if the username in val1 doesn't equal the
> username in val2. The important data here being "userX", other stuff I
> could care less about. Only thing I've come up with is doing a "count" of
> "cn" first and creating seperate input files and script for each "numbered"
> ou and I just don't want to :) Can someone morf mine into something that
> works? Many Thanks...
>
> DATA
>
> Matched 'cn=usera,cn=Recipients,ou=something,o=something else' to
> 'CN=usera,OU=office,OU=office2,OU=Users and Groups,DC=domain,DC=com' based
> on SID.
> Matched 'cn=userb,cn=Recipients,ou=somthing,o=something else' to
> 'CN=userb,OU=office,OU=office2,OU=Users and Groups,DC=domain,DC=com' based
> on SID.
> Matched 'cn=userc,cn=wayway,cn=outeast,ou=something,o=something else' to
> 'CN=userc,OU=outeast,OU=support,OU=Users and Groups,DC=domain,DC=com' based
> on SID.
>
> PARSE
> cat ez.log | grep Matched | awk -F"[Cc][Nn]=" '{print $2 $4}' | awk -F","
> '$1 != $2 {print $1","$2}'
As I understand the script you have, what you want is the first "cn=XXX,"
and "CN=YYY," fields on the line. The first awk is busting things apart
based on cn= or CN= as a separator, so we get the first line breaking as:
$1 = Matched '
$2 = usera,
$3 = Recipients,ou=something,o=something else' to '
$4 = usera,OU=office,OU=office2,OU=Users and Groups,DC=domain,DC=com' based
on SID.
The 2nd awk breaks lines apart based on ',', so it sees:
$1 = usera
$2 = usera
Things fall apart on the third line because there are three cn=XXX, fields,
and the count is off.
So, if there is always exactly one CN=YYY field (or if you want the last
one), the following change to your script should suffice:
grep Matched ez.log \
| awk -F"[Cc][Nn]=" '{print $2 $(NF)}' \
| awk -F"," '$1 != $2 {print $1","$2}'
That is, the first awk prints field 2 (after the first cn=) and the last
field (after the last CN=).
Another approach is to process it in shell (this one recognizes the first
cn= and the first CN= fields):
grep Matched ez.log | while read line
do cn=${line%*cn=} CN=${line%*CN=}
cn=${cn##,*} CN=${CN##,*}
[ "$cn" -ne "$CN" ] && echo "$cn,$CN"
done
Marcus Hall
marcus at tuells.org
More information about the clue-tech
mailing list