Event Timeline
Comment Actions
As suggested...
[foo@jumpspeeder ~]$ echo 'passwd: files nis sss' >~/nsswitch.conf
[foo@jumpspeeder ~]$ cat ~/nsswitch.conf
passwd: files nis sss
^
|
|
Look here...
[foo@jumpspeeder ~]$ ex -sc '%s/^\([[:space:]]\)*\(passwd:\|shadow:\)\([[:space:]]\)\+\(files\)\([[:space:]]\)\+nis\([[:space:]]\)\+\(sss\)/\1\2\3\4\5\6\7/' -c w -c q ~/nsswitch.conf
[foo@jumpspeeder ~]$ cat ~/nsswitch.conf
passwd: files sss
^
|
|
...here too.
Still no joy.
Thanks in advance.Comment Actions
Works like a charm...
[foo@jumpspeeder ~]$ echo 'passwd: files nis sss' >~/nsswitch.conf
[foo@jumpspeeder ~]$ cat -v ~/nsswitch.conf
passwd: files nis sss
^
|
|
Look here...
[foo@jumpspeeder ~]$ ex -sc 'g/^\([[:space:]]\)*\(passwd:\|shadow:\)/s/nis[[:space:]]//' -c w -c q ~/nsswitch.conf
[foo@jumpspeeder ~]$ cat -v ~/nsswitch.conf
passwd: files sss
^
|
|
...here too.
This'll do.
Thanks a lot for the sugestion/s.Comment Actions
I've a problem with 'sh -c' which doesn't seem to honor the '\(' character...
As a test (played with ~/nsswitch.conf before I edit the actual /etc/nsswitch.conf), here it throws out...
[foo@jumpspeeder ~]$ sudo -E -k sh -c 'a=~/nsswitch.conf; cp -fpv "${a}" "${a}".$(date +"%Y%m%d%H%M%S").baka; ex -sc 'g/^\([[:space:]]\)*\(passwd:\|shadow:\)/s/nis[[:space:]]//' -c w -c q "${a}"'
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `a=~/nsswitch.conf; cp -fpv "${a}" "${a}".$(date +"%Y%m%d%H%M%S").baka; ex -sc g/^([[:space:]])*(passwd:|shadow:)/s/nis[[:space:]]// -c w -c q "${a}"'
[foo@jumpspeeder ~]$
I'm fairly certain that the problem is in the 'ex -sc 'g/^\(' part... I just don't know the root cause.
Any tips on how to resolve this? Thanks in advance.Comment Actions
mr.a@razorcrest:~ % uname -ns
FreeBSD razorcrest
mr.a@razorcrest:~ % echo ${SHELL}
/bin/csh
mr.a@razorcrest:~ % sudo -k echo 'passwd: files nis sss'>/tmp/nsswitch.conf
mr.a@razorcrest:~ % sudo -k echo 'shadow: files nis sss'>>/tmp/nsswitch.conf
mr.a@razorcrest:~ % sudo -k cat /tmp/nsswitch.conf
passwd: files nis sss
shadow: files nis sss
mr.a@razorcrest:~ % sudo -k -E sh -c 'export a=/tmp/nsswitch.conf; cp -fpv "${a}" "${a}".$(date +"%Y%m%d%H%M%S").baka;' sudo -k ex -sc 'g/^\([[:space:]]\)*\(passwd:\|shadow:\)/s/nis[[:space:]]//' -c w -c q /tmp/nsswitch.conf
‘/tmp/nsswitch.conf’ -> ‘/tmp/nsswitch.conf.20200520103634.baka’
That doesn't seem to work...
[mr.a@jumpspeeder ~]$ sudo -k cat /tmp/nsswitch.conf
passwd: files nis sss
shadow: files nis sss
But when I elevate to Charlie Root...
[mr.a@jumpspeeder ~]$ sudo su -
..then do this (that the same set of commands, yeah),
[root@jumpspeeder ~]# ex -sc 'g/^\([[:space:]]\)*\(passwd:\|shadow:\)/s/nis[[:space:]]//' -c w -c q /tmp/nsswitch.conf
[root@jumpspeeder ~]# cat /tmp/nsswitch.conf
passwd: files sss
shadow: files sss
...target string 'nis' is gone.
This makes me scratch my head... tsk, tsk. I really want to stick to sudo all throughout the session, so please help me find what's wrong with my logic.
Thanks in advance,
mr.a