Solved

AWK Find and Replace

Posted on 2015-01-19
1
268 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
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wifi not working on Raspberry Pi 3? 2 51
Weird Samba Connectivity Issue... 7 39
php ssh2_scp_send 1 60
Backup & Restore 3 54
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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é.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now