regular expressions?

Discussion in 'Perl Misc' started by Ivan, May 17, 2007.

  1. Ivan

    Ivan Guest

    Hi all..

    I'm in need of some help..

    I'm looking after a subversion machine with many repositories and many
    users in the passwd files for each..

    Currently when I want to get rid of one of the users, I normally have
    to go through each repository, look in the passwd file and delete the
    user manually..

    I'm assuming with perl I might be able to make up a quick script that
    will look inside each repo, find the line with the user, delete it and
    save the file.. It will save a lot of my time..

    Either a perl script or a shell script might be suitable for this..
    All I got at the moment is the command line: grep -l "troppd" */conf/
    passwd
    So instead of going through hundreds of repositories, I only have to
    go into the ones where "troppd" appears and I can delete it..

    Would someone be able to give me an idea of what such script would
    look like?
    Either that, or tell me whether it's very hard to write or not ..
    I've not done perl in many years so I don't even know where to start..
    Ivan, May 17, 2007
    #1
    1. Advertising

  2. On Wed, 16 May 2007 18:53:45 -0700, Ivan wrote:

    > Hi all..
    >
    > I'm in need of some help..
    >
    > I'm looking after a subversion machine with many repositories and many
    > users in the passwd files for each..
    >
    > Currently when I want to get rid of one of the users, I normally have to
    > go through each repository, look in the passwd file and delete the user
    > manually..
    >
    > I'm assuming with perl I might be able to make up a quick script that
    > will look inside each repo, find the line with the user, delete it and
    > save the file.. It will save a lot of my time..
    >
    > Either a perl script or a shell script might be suitable for this.. All
    > I got at the moment is the command line: grep -l "troppd" */conf/ passwd
    > So instead of going through hundreds of repositories, I only have to go
    > into the ones where "troppd" appears and I can delete it..


    Here's how I would do this. I assume these passwd files are regular
    passwd files, so I can assume the username starts at the beginning of the
    line followed by a colon. If this is assumption is not correct, slight
    modifications will be needed to the regexps.

    $TODELETE="troppd"
    perl -n -i.bak -e "/^$TODELETE:/ or print" \
    $(grep -l "^$TODELETE:" */conf/ passwd)

    This can also be solved easily with sed or awk, but perl has a convenient
    in-place edit with the -i switch. See perldoc perlrun for a description
    of these switches.

    Also note that this only modifies the files that do contain the user,
    which you most probably will want. Otherwise leave out the grep part and
    operate on */conf/passwd directly.

    As the above is untested code, I would test thoroughly before running
    this in production!

    HTH,
    M4
    Martijn Lievaart, May 17, 2007
    #2
    1. Advertising

  3. On May 17, 2:53 am, Ivan <> wrote:

    > Subject: regular expressions?


    Please put the subject of your post in the Subject of your post.
    Brian McCauley, May 17, 2007
    #3
  4. Ivan

    Ivan Guest

    On May 17, 10:29 pm, Martijn Lievaart <> wrote:
    > On Wed, 16 May 2007 18:53:45 -0700, Ivan wrote:
    > > Hi all..

    >
    > > I'm in need of some help..

    >
    > > I'm looking after a subversion machine with many repositories and many
    > > users in the passwd files for each..

    >
    > > Currently when I want to get rid of one of the users, I normally have to
    > > go through each repository, look in the passwd file and delete the user
    > > manually..

    >
    > > I'm assuming with perl I might be able to make up a quick script that
    > > will look inside each repo, find the line with the user, delete it and
    > > save the file.. It will save a lot of my time..

    >
    > > Either a perl script or a shell script might be suitable for this.. All
    > > I got at the moment is the command line: grep -l "troppd" */conf/ passwd
    > > So instead of going through hundreds of repositories, I only have to go
    > > into the ones where "troppd" appears and I can delete it..

    >
    > Here's how I would do this. I assume these passwd files are regular
    > passwd files, so I can assume the username starts at the beginning of the
    > line followed by a colon. If this is assumption is not correct, slight
    > modifications will be needed to the regexps.
    >
    > $TODELETE="troppd"
    > perl -n -i.bak -e "/^$TODELETE:/ or print" \
    > $(grep -l "^$TODELETE:" */conf/ passwd)
    >
    > This can also be solved easily with sed or awk, but perl has a convenient
    > in-place edit with the -i switch. See perldoc perlrun for a description
    > of these switches.
    >
    > Also note that this only modifies the files that do contain the user,
    > which you most probably will want. Otherwise leave out the grep part and
    > operate on */conf/passwd directly.
    >
    > As the above is untested code, I would test thoroughly before running
    > this in production!
    >
    > HTH,
    > M4




    Hi there..
    Thank you kindly for your reply ..
    I did in fact got it working (using sed, not awk) .. But it works just
    fine ..
    Not knowing much of perl, I will look at your script and try to make
    most sense of it, as it looks a bit more robust than the single line
    of sed coding .


    Cheers,

    Ivan.
    Ivan, May 18, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Douglas

    Custom Regular Expressions in ASP.net

    Jay Douglas, Nov 2, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    595
    mikeb
    Nov 3, 2003
  2. mark

    Regular expressions

    mark, Jun 30, 2003, in forum: Perl
    Replies:
    4
    Views:
    1,710
  3. Dustin D.
    Replies:
    1
    Views:
    11,140
  4. Jay Douglas
    Replies:
    0
    Views:
    591
    Jay Douglas
    Aug 15, 2003
  5. Noman Shapiro
    Replies:
    0
    Views:
    218
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page