Solved

AWK Find and Replace

Posted on 2015-01-19
1
278 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

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

Suggested Solutions

Title # Comments Views Activity
Upgrade BIOS / EUFI at Scale 4 69
expand ext4 on centos 6 5 52
Internal CA server 6 88
Linux MD5 Hash 7 59
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…
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

685 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