[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

perl one liner

Posted on 2011-04-26
10
Medium Priority
?
448 Views
Last Modified: 2012-05-11
I need to delted an "additional root user" out of /etc/passwd and /etc/shadow.

I would prefer just to lock the account but that is another issue, I have to delete.

How do I delete the line that has user name  Root_n_tooten

Perl one liners work great for me

I assume it will look something like

perl -i  -pe 's/^(root-n-tooten)/#$1/' file
but it would not comment out , it would remove the line






0
Comment
Question by:TIMFOX123
  • 5
  • 3
  • 2
10 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 35467644
It works for me.
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35467648
So do you want to comment it or delete the line?  It is commenting out correctly.
0
 
LVL 81

Expert Comment

by:arnold
ID: 35467698
userdell root-n-tooten

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:TIMFOX123
ID: 35467801
I need to delete the line

userdell has taken both users away and the people that own the box are not happy when the root account gets deleted.  

thank you
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35467880
Try this,
sed -i /root-n-tooten/d /etc/passwd
 sed -i /root-n-tooten/d /etc/shadow

Open in new window

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35467892
Or if you want to make sure that it is in the beginning of the line
sed -i /^root-n-tooten/d /etc/passwd
sed -i /^root-n-tooten/d /etc/shadow

Open in new window

0
 
LVL 81

Expert Comment

by:arnold
ID: 35468122
perhaps the userdell 'root\-n\-tooten' is a better approach to make sure that the - is not treated as an argument to userdel.

You only need to remove the entry from /etc/passwd and then run pwconv which will synchronize the /etc/shadow entries based on the entries in /etc/passwd/

farzani's sed works.
0
 

Author Comment

by:TIMFOX123
ID: 35468406
what do I do about this when I try to run that :

$ sed: illegal option -- i

this has to work in aix, solaris and linux

0
 
LVL 31

Accepted Solution

by:
farzanj earned 2000 total points
ID: 35468471
Oops, you have older version of sed.

Try this instead:

perl -ni -e 'print unless /^root-n-tooten/' /etc/passwd
perl -ni -e 'print unless /^root-n-tooten/' /etc/shadow

Open in new window

0
 

Author Closing Comment

by:TIMFOX123
ID: 35468555
thank you

very much

this works !~!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Six Sigma Control Plans
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

864 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