Operating System - HP-UX
1830309 Members
2089 Online
110000 Solutions
New Discussion

Script for changing root passwd

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Script for changing root passwd

HI,
I would like to write a script to change the root passwd in /etc/passwd on every machine on a monthly basis i.e the 1st day of the month.

But I'm really unsure how I could just access the 1st line in the /etc/passwd file which contains the entry for root and its encrypted passwd. I'd then like to modify the second field for root's entry (the encrypted passwd) to a new value.

The new passwd value is to be read from a file.

Could someone show me how the script should be written in AWK or any other scripting languages? I need to also check that for every begining of the month, the passwd should be modified.

Could someone kindly help me out? I'm still a newbie to scripting.

Thanks


3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: Script for changing root passwd

Jean-Louis Phelix
Honored Contributor

Re: Script for changing root passwd

Hi,

This script should d it :

/tmp/NEW contains the new password. I use vipw to add security check after modification. Just in case ...

Regards.

#!/usr/bin/sh
[ $(date +'%d') != 1 ] &&
{
echo not first day of month ...
exit 1
}
NEWPASS=$(cat /tmp/NEW)
vipw <<+++
/^root:
f:lct:$NEWPASSx!
+++
It works for me (© Bill McNAMARA ...)
Jean-Louis Phelix
Honored Contributor

Re: Script for changing root passwd

hi

Cut and Paste problem

f:lct:$NEWPASSx!

should have an ESC (use CTRL-V then ESC)inserted before last x :

f:lct:$NEWPASS^[x!

Regards.
It works for me (© Bill McNAMARA ...)