CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
need help trying to perfect a filtering multiple file content

 



pengboi
New User

Apr 14, 2017, 7:23 AM

Post #1 of 4 (3806 views)
need help trying to perfect a filtering multiple file content Can't Post

trying to extract groups that have only a member from each *.group file which contains list of groups and their members in a PASSGRP directory(the directory contains multiple *.passwd and *group files) add them to the group.ignore file and redirect the remaining groups with multiple users into a new $file foreach *.group file keeping the name of the original file.attached below is what i have.need help perfecting it.thanks
Attachments: groupfilter.txt (1.40 KB)


BillKSmith
Veteran

Apr 15, 2017, 12:17 PM

Post #2 of 4 (3787 views)
Re: [pengboi] need help trying to perfect a filtering multiple file content [In reply to] Can't Post

This is how I understand your problem. Please correct me where I am wrong.

The PASSGRP directory contains multiple *.passwd and *group files

Each of the .group files contains a list of groups and their members.

For each .group file in PASSGRP directory you must:

  • Remove groups, that have only a member (or are already in .ignore file)


  • Append those groups to the group.ignore file.


  • The code you provide has only one output file. It contains a list of groups. I cannot tell if these are the groups that you wish to append to the .ignore or if it is a list of all other groups. (I do not see anything in your code or text about how to tell how many users are in a group)

    You probably need help with editing the .group files. This is a bit tricky. Lets get the requirements right before I try to explain it.

    You can append to the .ignore file by opening it in append mode.
    Good Luck,
    Bill


    pengboi
    New User

    Apr 20, 2017, 10:33 AM

    Post #3 of 4 (3748 views)
    Re: [BillKSmith] need help trying to perfect a filtering multiple file content [In reply to] Can't Post

    i want the output file to be other groups and append the groups with single users to the ignore file.
    one of the group files example: cat /PASSGRP/server1.group

    adm:!:4:bin,adm,root
    uucp:!:5:uucp,nuucp
    mail:!:7:
    security:!:7:root,a***,a***,a***,a***,a***,a***,a****,a****,a****,a***,a***,a****,a****,a****
    cron:!:8:root
    printq:!:9:lp
    audit:!:10:root,svqradar
    ecs:!:18:
    nobody:!:4294967294:nobody,lpd
    usr:!:100:
    perf:!:20:
    sshd:!:209:sshd

    i will like the output of the script to append this groups with more than 1 user to a new server1.group file

    security:!:7:root,a***,a***,a***,a***,a***,a***,a****,a****,a****,a***,a***,a****,a****,a****
    adm:!:4:bin,adm,root
    uucp:!:5:uucp,nuucp
    audit:!:10:root,svqradar


    remove the following lines and append the group name to group.ignore file. because they either have no members or have just themselfs as the only member.

    sshd:!:209:sshd
    usr:!:100:
    perf:!:20:
    cron:!:8:root
    printq:!:9:lp
    ecs:!:18:
    mail:!:7:

    if it is possible to filter by lines or however you see i can complete this.

    thanks in advance


    (This post was edited by pengboi on Apr 20, 2017, 10:34 AM)


    BillKSmith
    Veteran

    Apr 21, 2017, 8:17 AM

    Post #4 of 4 (3713 views)
    Re: [pengboi] need help trying to perfect a filtering multiple file content [In reply to] Can't Post

    You have not defined 'group' or 'member'. From your example, I can infer that each line of your .group file consists of a group name optionally followed by a comma-separated list of members. You want to write each line to either the 'server' file or the 'ignore' file depending on the number of members. (The line 'nobody' seems to be an exception. Is this a mistake in your example or have I missed something?)

    Open the server file in output mode.
    Open the ignore file in append mode.

    For each .group file
    Open the .group file in input mode.
    Read it one line at a time.
    If the line contains a comma:
    Write the line to the 'server' file.
    Else
    Write it to the 'ignore' file.

    At end of file, close the .group file

    After all group files have been read
    Close both output files.

    This does not remove any lines from the .group file. I am still not clear enough on requirements to address that issue.
    Good Luck,
    Bill

     
     


    Search for (options) Powered by Gossamer Forum v.1.2.0

    Web Applications & Managed Hosting Powered by Gossamer Threads
    Visit our Mailing List Archives