regular expressions?

I

Ivan

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..
 
M

Martijn Lievaart

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
 
I

Ivan

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top