Tuesday, November 5, 2013

Striping starting and trailing character of each line in a file

sed -i.backup 's/^.\(.*\).$/\1/' filename

sed -i.backup 's/^.\(.*\)".$/\1/'  filename

2 comments:

  1. My /etc/pam.d/system-auth-ac has the below auth parameters set:

    auth required pam_env.so
    auth sufficient pam_fprintd.so
    auth sufficient pam_unix.so nullok try_first_pass
    auth requisite pam_succeed_if.so uid >= 500 quiet
    auth required pam_deny.so

    account required pam_unix.so
    account sufficient pam_localuser.so
    account sufficient pam_succeed_if.so uid < 500 quiet
    account required pam_permit.so

    password required pam_cracklib.so retry=3 minlen=12 difok=4
    password required pam_unix.so md5 remember=12 use_authtok
    #password requisite pam_cracklib.so try_first_pass retry=3 type=
    #password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok
    password required pam_deny.so

    session optional pam_keyinit.so revoke
    session required pam_limits.so
    session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
    session required pam_unix.so








    I want to edit highlighted lines from the file by using function.
    auth required pam_env.so
    auth required pam_tally2.so onerr=fail file=/var/log/faillog deny=6 unlock_time=3600
    auth sufficient pam_fprintd.so
    auth sufficient pam_unix.so nullok try_first_pass
    auth requisite pam_succeed_if.so uid >= 500 quiet
    auth required pam_deny.so
    account required pam_unix.so
    account required pam_tally2.so file=/var/log/faillog
    account sufficient pam_localuser.so
    account sufficient pam_succeed_if.so uid < 500 quiet
    account required pam_permit.so
    password requisite pam_cracklib.so try_first_pass retry=3 minlen=8 lcredit=-1 dcredit=1 difok=4 maxrepeat=2 ocredit=1 ucredit=1
    password sufficient pam_unix.so shadow try_first_pass use_authtok remember=6
    password required pam_deny.so

    session optional pam_keyinit.so revoke
    session required pam_limits.so
    session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
    session required pam_unix.so
    Function used to edit lines from script: shows error, we also need to add all lines in this function.
    #! /bin/bash

    grep "pam_tally2" /etc/pam.d/system-auth-ac &> /dev/null
    if [ $? -ne 0 ];
    then
    sed -i '/^[ ]*auth[ ]*required[ ]*pam_env.so/aauth\trequired\tpam_tally2.so onerr=failfile=/var/log/failog deny=6 unlock_time=3600' /etc/pam.d/system-auth-ac
    else
    sed -i 's/.*pam_tally2.*/auth\trequired\tpam_tally2.so onerr=failfile=/var/log/faillog deny=6 unlock_time=3600/1' /etc/pam.d/system-auth-ac
    fi
    My task is to edit these lines from pam.d/system/auth-ac file
    pam_tally2.so onerr=fail file=/var/log/faillog deny=6 unlock_time=3600
    account required pam_tally2.so file=/var/log/faillog
    password requisite pam_cracklib.so try_first_pass retry=3 minlen=8 lcredit=-1 dcredit=1 difok=4 maxrepeat=2 ocredit=1 ucredit=1
    password sufficient pam_unix.so shadow try_first_pass use_authtok remember=6



    ReplyDelete

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.