LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-16-2012, 11:00 AM   #1
bkone
Member
 
Registered: Jun 2006
Distribution: Suse
Posts: 74

Rep: Reputation: 15
sed help to run sed command against multiple different file names


I am not sure if there is an easier way to do this but probably. I have several 25+ servers in which we had connected to AD using Samba and Winbind. On the servers that we no longer use Samba on the Samba packages were removed. I am trying to comment out the line that contained pam.winbind.so in the following files:
/etc/pam.d/common-auth
/etc/pam.d/common-account
/etc/pam.d/common-password
/etc/pam.d/common-session

I am running SUSE Linux Enterprise 11. I thought I could throw these lines in a bash script but they don't all run.
Code:
#!/bin/bash
sed -i '/auth   required        pam_winbind.so/,/<\/auth/s/^/#/' /etc/pam.d/common-auth
sed -i '/session   required        pam_winbind.so/,/<\/session/s/^/#/' /etc/pam.d/common-session
sed -i '/account   required        pam_winbind.so/,/<\/account/s/^/#/' /etc/pam.d/common-account
sed -i '/password   required        pam_winbind.so/,/<\/password/s/^/#/' /etc/pam.d/common-password
Just the first line works. I was trying to just comment out the line but now I am up to deleting them or whatever is easier and faster.

Any suggestions from the pros?
 
Old 04-16-2012, 11:55 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,516

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
I have 2 questions:

1. pam_winbind.so - does this string only appear on the lines to be commented out?

2. Are all the files being changed the only ones in the directory starting with the string 'common'?

If the answer is yes to both, I would use:
Code:
sed -i '/pam_winbind.so/s/^/#/' /etc/pam.d/common-*
 
Old 04-16-2012, 12:27 PM   #3
bkone
Member
 
Registered: Jun 2006
Distribution: Suse
Posts: 74

Original Poster
Rep: Reputation: 15
Brillant!

Thanks grail.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how we can find and replace multiple file using sed command jayakumar01 Linux - Server 1 04-05-2012 07:53 AM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 07:59 AM
Sed Command - - -How to change part of the name of multiple files sahil.jammu Linux - Newbie 6 04-02-2009 10:57 PM
combining multiple sed operations into a single command kushalkoolwal Programming 3 09-16-2008 05:58 PM
Could not run SED command mmunir Other *NIX 3 05-05-2008 06:07 AM


All times are GMT -5. The time now is 11:37 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration