LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed help to run sed command against multiple different file names (http://www.linuxquestions.org/questions/programming-9/sed-help-to-run-sed-command-against-multiple-different-file-names-940066/)

bkone 04-16-2012 11:00 AM

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? :)

grail 04-16-2012 11:55 AM

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-*

bkone 04-16-2012 12:27 PM

Brillant!

Thanks grail.


All times are GMT -5. The time now is 04:54 PM.