Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: in place editing by variables

by 2teez (Vicar)
on Apr 11, 2013 at 19:13 UTC ( #1028210=note: print w/replies, xml ) Need Help??

in reply to in place editing by variables

"...I am focus on user1 in the script below but would also like to see a script example if I wanted to in place edit user1 and user3..."

I agree with hdb and others totally here, however, if you still want to practice with your originally Posted data as shown in your post. You can go through the line one by one substituting for user1 and user3 like so:

use warnings; use strict; while(<DATA>){ chomp; if(/^user(1|3):/){ s{(?<=/bin)(.+?)$}{/nologin}; } print $_,$/; } __DATA__ user1:x:9760822:3241:USER 1:/home/user1:/bin/bash user2:x:9760822:3242:USER 2:/home/user2:/bin/ksh user3:x:9760822:3243:USER 3:/home/user3:/bin/sh
user1:x:9760822:3241:USER 1:/home/user1:/bin/nologin user2:x:9760822:3242:USER 2:/home/user2:/bin/ksh user3:x:9760822:3243:USER 3:/home/user3:/bin/nologin

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: in place editing by variables
by cp890 (Initiate) on Apr 11, 2013 at 22:06 UTC

    thanks for all your responses- I have at least one OS if a process is running - the usermod returns in use. I cant always bring down the app or db associated. some of servers i can use vipw which works, but is manual and subject to more errors and some servers and OS do not have vipw- this is why i going with the script and backup

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028210]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2018-03-21 09:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (265 votes). Check out past polls.