AIX sed/awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX sed/awk
# 1  
Old 01-22-2013
AIX sed/awk

I'm trying to change the pam.conf file like below.

Code:
ssh     auth    required        /usr/lib/security/pam_prohibit
ssh     account required        /usr/lib/security/pam_prohibit
emagent auth    required        /usr/lib/security/pam_prohibit
emagent account required        /usr/lib/security/pam_prohibit

to

Code:
ssh     auth    required        /usr/lib/security/pam_aix
ssh     account required        /usr/lib/security/pam_aix
emagent auth    required        /usr/lib/security/pam_aix
emagent account required        /usr/lib/security/pam_aix

As suggest on previous forum I tried

Code:
cat /etc/pam.conf | \
awk '$1=="ssh"||$1=="emagent"{sub("prohibit","aix",$NF);}1' > /etc/pam.conf

It is working fine but changing the content with format as below.


Code:
authexec        session required        /usr/lib/security/pam_prohibit
sshd    auth    required        /usr/lib/security/pam_prohibit
sshd    account required        /usr/lib/security/pam_prohibit
sshd    password        required        /usr/lib/security/pam_prohibit
sshd    session required        /usr/lib/security/pam_prohibit
ssh auth required /usr/lib/security/pam_aix
ssh account required /usr/lib/security/pam_aix
ssh password required /usr/lib/security/pam_aix
ssh session required /usr/lib/security/pam_aix
emagent auth required /usr/lib/security/pam_aix
emagent account required /usr/lib/security/pam_aix
emagent password required /usr/lib/security/pam_aix
emagent session required /usr/lib/security/pam_aix

Is there any way that we could use sed -i for this or awk without changing the format?
# 2  
Old 01-22-2013
Can you set OFS and re-try?
Code:
awk -FS='\t' '$1=="ssh"||$1=="emagent"{sub("prohibit","aix",$NF);}1' OFS='\t' /etc/pam.conf

# 3  
Old 01-22-2013
Code:
cat /etc/pam.conf | \
awk '$1=="ssh"||$1=="emagent"{sub("prohibit","aix",$NF);}1' OFS='\t' > /etc/pam.conf


The above worked. I really appreciate your help. Would you mind explaining me the whole command above?

Thanks a lot.
# 4  
Old 01-22-2013
Quote:
Originally Posted by pjeedu2247
Code:
cat /etc/pam.conf | \
awk '$1=="ssh"||$1=="emagent"{sub("prohibit","aix",$NF);}1' OFS='\t' > /etc/pam.conf


The above worked. I really appreciate your help. Would you mind explaining me the whole command above?

Thanks a lot.
The command bipinajith supplied:
Code:
awk -FS='\t' '$1=="ssh"||$1=="emagent"{sub("prohibit","aix",$NF);}1' OFS='\t' /etc/pam.conf

reads lines from /etc/pam.conf and for any line where the first field is exactly the string ssh or the string emagent it replaces the string prohibit in the last field in the line with the stringaix. It then writes the updated file to standard output (usually the terminal where you run the command) unless you redirect the output to a different file.

The pipeline that you say is working should turn the file /etc/pam.conf into an empty file. The pipeline uses that file both as an input file and as an output file. When you do this, the shell will throw away the current contents of the file before starting cat to feed the (now empty) contents of the file into awk.
# 5  
Old 01-22-2013
That makes complete sense. I really appreciate your effort. Thanks again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX sed use space as delimiter

I am trying to do this with one small tweak. I would also like to use a space as a delimiter. sed 's/ */\ /g' file This is what my file looks like. server1, server2, server3 server4 server5 server6 I would like it to look like this. server1 server2 server3 server4 ... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

sed and awk giving error ./sample.sh: line 13: sed: command not found

Hi, I am running a script sample.sh in bash environment .In the script i am using sed and awk commands which when executed individually from terminal they are getting executed normally but when i give these sed and awk commands in the script it is giving the below errors :- ./sample.sh: line... (12 Replies)
Discussion started by: satishmallidi
12 Replies

3. Shell Programming and Scripting

Inconsistent behaviour of sed - UNIX AIX 5.3

Hi there. I'm facing a strange & an intriguing behaviour with sed while replacing the tab character with a space reading from a file. It randomly works sometimes but mostly doesn't work. Below is what's happening- <tab> here is the actual literal tab. user1> cat temp2 1<tab>2<tab>3 4... (2 Replies)
Discussion started by: Deepak.Dhami
2 Replies

4. Shell Programming and Scripting

AIX pam ssh/sshd configuration not allowing sed or awk

This is a weird problem. Following is my code. /opt/quest/bin/vastool configure pam sshd /opt/quest/bin/vastool configure pam ssh cat /etc/pam.conf | \ awk '$1=="ssh"||$1=="sshd"||$1=="emagent"{sub("prohibit","aix",$NF);}1' OFS='\t' > /etc/pam.conf cat /etc/ssh/sshd_config | \ sed -e... (2 Replies)
Discussion started by: pjeedu2247
2 Replies

5. Shell Programming and Scripting

Alternate for sed -i in AIX

Experts, At the moment I am working in AIX box where sed -i is not available. My requirement is as below Two files file1 and file2. file1 contains the IP address, its count. file2 contains the Hostname and its corresponding IP address. I would like get the IP address replaced with the apt... (7 Replies)
Discussion started by: sathyaonnuix
7 Replies

6. UNIX for Dummies Questions & Answers

Unable to run Sed in AIX

Hi All, I've wrote a script to truncate newline characters in a text file. Could you please help me in figuring out the issue :confused: for file in $Filelist; do echo $file; FileName=`basename $file`; sed 's/^M//g' $file> "${file}"2; mv "${file}"2 "${file}"; sed '1d' "${file}"... (5 Replies)
Discussion started by: udayakumar
5 Replies

7. Shell Programming and Scripting

SED on AIX Limitation

Hello, I have a problem running a script created in ksh for Linux (Tested on Debian 5.0, Ubuntu Server 10.04 and RHEL 5.1), it works properly. :b: I trying to pass it to a AIX 5.3. :wall: The problem is the character limit of 256 on a command system and SED. I need to cut the contents of... (8 Replies)
Discussion started by: nemesis.spa
8 Replies

8. Shell Programming and Scripting

Sed or Awk for modify hour in a crontab AIX

Hi, I want to modifiy the hour in the crontab AIX 5.3 for this line: Input: 00 22 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 Output: 30 20 * * * /outillage/script_exploit/bin/SavOffline.ksh > /dev/null 2>&1 With the awk or sed function through a ssh -q... (1 Reply)
Discussion started by: khalidou13
1 Replies

9. Shell Programming and Scripting

AIX Korn shell sed -s problem

In a Korn shell script I have, cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt The header is short {{Company flag1}} But the result in header.txt is {{Company $cnumb}} The value of $cnumb is 120. I am trying to get the value of $cnumb into the header. I have tried /'$cnumb'/g,... (10 Replies)
Discussion started by: jcarrott
10 Replies

10. Shell Programming and Scripting

sed -r problem in AIX

Hi All, I have one doubt in the AIX. I executed the below command in the LINUX but i could not execute same thing in the AIX. Please see the details of my issue in below. # cat test line 1 (one) line 2 (two) build=test line 3 (three) # sed -r 's/build=\w+/build=new_build/' test line 1... (7 Replies)
Discussion started by: sridhusha
7 Replies
Login or Register to Ask a Question