Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: in place editing by variables

by 2teez (Priest)
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 having an uproarious good time at the Monastery: (1)
As of 2017-09-23 11:31 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (272 votes). Check out past polls.