Operating System - HP-UX
1753851 Members
9428 Online
108808 Solutions
New Discussion юеВ

Re: awk or other command help

 
SOLVED
Go to solution
rhansen
Frequent Advisor

awk or other command help

Hello,

I am trying to figure out if a user is part of a group or not for many servers. I have a repository of the servers at a central location /tmp/type/*/group.

Where type is variable and * are hundres of servers i.e. /tmp/servers/JRA/*/group.

I want to check if ID JRA is a part of group JRA_W on all of these servers. Can someone help me with a single command to achieve this.

Thanks in advance!
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: awk or other command help

Hi:

This might be as simple as :

# awk '/JRA/ && /^JRA_W:/' {print FILENAME":",$0}' /tmp/type/*/group

Regards!

...JRF...
rhansen
Frequent Advisor

Re: awk or other command help

# awk '/JRA/ && /^JRA_W:/' {print FILENAME":",$0}' /tmp/type/*/group
When I try this it gets me a
>

What does the FILENAME does in the code.

Thanks.
Patrick Wallek
Honored Contributor
Solution

Re: awk or other command help

There is one to many ' in the command. Try this:

awk '/JRA/ && /^JRA_W:/ {print FILENAME":",$0}' /tmp/type/*/group
James R. Ferguson
Acclaimed Contributor

Re: awk or other command help

Hi (again):

Sorry a typo. The command should be:

# awk '/JRA/ && /^JRA_W:/ {print FILENAME":",$0}' /tmp/type/*/group

The 'FILENAME' is 'awk's current file name being processed. This adds the name of the file that has matching criteria to the output followed by a colon and the line that matched.

Regards!

...JRF...
rhansen
Frequent Advisor

Re: awk or other command help

Thanks James and Patrick for the help. The command gets me the output but not what I desire. Sorry, I may not have been clear enough.

I only need to find the servers where JRA ID is not a part of JRA_W group so that I can add it to the group. This currently gives me everything.
Patrick Wallek
Honored Contributor

Re: awk or other command help

OK, try this then:


awk '!/JRA/ && /^JRA_W:/ {print FILENAME":",$0}' /tmp/type/*/group

This should give you the files where JRA is NOT part of JRA_W.
James R. Ferguson
Acclaimed Contributor

Re: awk or other command help

Hi (again):

> I only need to find the servers where JRA ID is not a part of JRA_W group so that I can add it to the group. This currently gives me everything.

Then:

# awk '/^JRA_W:/ && !/JRA/ {print FILENAME}' /tmp/type/*/group | sort -u

Regards!

...JRF...
rhansen
Frequent Advisor

Re: awk or other command help

Thanks James, that worked perfectly.