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

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
Output:
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


Comment on Re: in place editing by variables
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028210]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-22 01:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (177 votes), past polls