Operating System - HP-UX
1753905 Members
9798 Online
108810 Solutions
New Discussion юеВ

Add a string at the end of a specific line

 
SOLVED
Go to solution
Andrew_80
Advisor

Add a string at the end of a specific line

I like to add a string 'sys' in the /etc/group file to the end of this line

sshd::102:


The reason I like to do it to over 20 servers and I like just to remsh and use ksh to handle it, How can I do that ?
The Sky is the Limit
7 REPLIES 7
Mel Burslan
Honored Contributor

Re: Add a string at the end of a specific line

echo "sshd::102:" >> /etc/group

should do it.

HTH
________________________________
UNIX because I majored in cryptology...
Mel Burslan
Honored Contributor
Solution

Re: Add a string at the end of a specific line

sorry misunderstood the question...

cmnd="sed -e 1,$s/sshd::102:/sshd::102:sys/ /etc/group > /tmp/dummy; cat /tmp/dummy > /etc/group"

then

remsh server_name $cmnd

HTH
________________________________
UNIX because I majored in cryptology...
Sridhar Bhaskarla
Honored Contributor

Re: Add a string at the end of a specific line

Hi,

It's better to use user|groupmod commands to interface the passwd and group files than editing them manually.

I would run the command

usermod -G 102 sys

This should add sys to sshd group in /etc/group.

Use remsh to run this command on all the servers.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Rodney Hills
Honored Contributor

Re: Add a string at the end of a specific line

How about using perl-

perl -pe '/^ssh/ && s/$/sys/' /etc/group

HTH

-- Rod Hills
There be dragons...
Andrew_80
Advisor

Re: Add a string at the end of a specific line

I actually like to add 'sys' to the line and I need to add just 'sys' to the group sshd . So at the end it should look like that:

sshd::102:sys

Thanks
The Sky is the Limit
curt larson_1
Honored Contributor

Re: Add a string at the end of a specific line

or you can use ex

ex -s +'1,$ s/^ssh::102:$/&sys/ | wq!' /etc/group
Andrew_80
Advisor

Re: Add a string at the end of a specific line

Thanks for the quick response, I used Rodney's suggestion using perl from command line and it worked Great !
Thanks a lot...
The Sky is the Limit