Need advice for modifying passwd file in shell script

Need advice for modifying passwd file in shell script

Post by R. Stacy Sherm » Sun, 16 Feb 1997 04:00:00



I'm writing a shell script that locks out users by putting a *LK* in the
/etc/passwd file.  I know this is a potentially dangerous thing and I want
to know how to handle it right.

What I'll probably do is copy the password file to a temp file, to all the
modifications there and then replace the passwd file.  I need to know what
else needs to be done so that things go right.  I think I read something
about using a makepasswd command to rebuild the password database?

This script will run on SunOS and there is a shadow file although I'm not
modifying it.

Any advice?

Thanks,

Stacy

 
 
 

Need advice for modifying passwd file in shell script

Post by Icarus Spar » Mon, 17 Feb 1997 04:00:00




Quote:>I'm writing a shell script that locks out users by putting a *LK* in the
>/etc/passwd file.  I know this is a potentially dangerous thing and I want
>to know how to handle it right.

>What I'll probably do is copy the password file to a temp file, to all the
>modifications there and then replace the passwd file.  I need to know what
>else needs to be done so that things go right.  I think I read something
>about using a makepasswd command to rebuild the password database?

A nice easy problem, unlike many that we get involing the password file!
All you need to do is create a script which does the edit to a file specified
as the first parameter, and then invoke 'vipw' with $EDITOR set to the name
of the script. You even have standard input available if you want it. 'vipw'
will do all the needed file locking, rebuilding databases etc as required.

A sample script would be

#!/bin/sh
ex - $1 <<!
/^fred:/s/:[^:]*/:*LK*:/
/^joe:/s/:[^:]*/:*LK*:/
w
q
!

Icarus

 
 
 

Need advice for modifying passwd file in shell script

Post by Somckit Khemmanivan » Tue, 18 Feb 1997 04:00:00





> >I'm writing a shell script that locks out users by putting a *LK* in the
> >/etc/passwd file.  I know this is a potentially dangerous thing and I want
> >to know how to handle it right.

> >What I'll probably do is copy the password file to a temp file, to all the
> >modifications there and then replace the passwd file.  I need to know what
> >else needs to be done so that things go right.  I think I read something
> >about using a makepasswd command to rebuild the password database?

> A nice easy problem, unlike many that we get involing the password file!
> All you need to do is create a script which does the edit to a file specified
> as the first parameter, and then invoke 'vipw' with $EDITOR set to the name
> of the script. You even have standard input available if you want it. 'vipw'
> will do all the needed file locking, rebuilding databases etc as required.

> A sample script would be

> #!/bin/sh
> ex - $1 <<!
> /^fred:/s/:[^:]*/:*LK*:/
> /^joe:/s/:[^:]*/:*LK*:/
> w
> q
> !

> Icarus

Check to see if your passwd command supports the -l option. This will
put the *LK* in the /etc/passwd file for you.

--

 
 
 

1. Unix Shell Script for modifying a file

Can any one help me in writing a shell script to open a file , insert a
number after the given position .

For Example : my file file.sh contains

1:H001:10:400:500:20:30
2:H002:30:600:700:40:50
3:H003:40:800:900:50:60

I want to insert zero after the position 4th in all the
rows , the final file should be like this .

file.sh

1:H001:10:400:0:500:20:30
2:H002:30:600:0:700:40:50
3:H003:40:800:0:900:50:60

2. httpd through cron

3. Bash Shell Script Problems - Advice Needed

4. SSA02 error code

5. Advice on shell script to output only lines that do not exist in file

6. sparc ultra 60 won't boot from external CDROM

7. making a iso image using mkhybrid (and getting errors)

8. Need a passwd file verify script.

9. Copy files using filenames from text files with shell script or bash script

10. need a modified passwd command on Solaris

11. Modifying passwd file with vi?

12. How to modify ascii text file (/etc/passwd)