?
Solved

AWK Find and Replace

Posted on 2015-01-19
1
Medium Priority
?
296 Views
Last Modified: 2015-01-19
I am new in awk and i want to replace a whole line. Its a part of the hardening script.

in /etc/pam.d/system-auth i need to change some configurations entry:

so there is a line called password requisite pam_cracklib.so

and it needed to change to password required pam_cracklib.so ...

So i thought i try to find first if there is already the line password required before i replace it, but i can not find the right way.

How is this been done, maybe on a different way???
0
Comment
Question by:Wilder_Admin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 40557591
You should use "sed" instead of "awk". As opposed to "awk" GNU "sed" on Linux can change the content of files "in place" (sort of).

sed -i.bak 's/password requisite pam_cracklib.so/password required pam_cracklib.so/' /etc/pam.d/system-auth

The flag "-i.bak" will instruct "sed" to create an unchanged backup file "system-auth.bak" before making the actual changes.

There is no need to check if the desired string is already present - if the "old" string is not there nothing will be changed.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question