Operating System - HP-UX
1850137 Members
2838 Online
104050 Solutions
New Discussion

Re: automating passwd in script

 
SOLVED
Go to solution
Chris Harris
Contributor

automating passwd in script

trying to automate activating users with a script. example should explain things. (not working by the way)

passwd $1 <<-END
$2
$2
END
4 REPLIES 4
Craig Rants
Honored Contributor

Re: automating passwd in script

Chris,
To do what you want, look at the expect programing language.

However if you want to automate some scripts or something try .rhosts file or .shosts file (for ssh). Ssh would be preffered for security reasons.

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Sridhar Bhaskarla
Honored Contributor
Solution

Re: automating passwd in script

Hi Chris,

We had a discussion on this one before. Have a look at this thread.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,11866,0x23cecf38d6bdd5118ff10090279cd0f9,00.html

I am using expect to automate the password changes across the systems with a combination of ssh.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Bill Hassell
Honored Contributor

Re: automating passwd in script

Usinge the 'expect' program will work, or you can use the enclosed program (ompiles on all versions of HP-UX) to create a simple password. (NOTE: Trusted Systems require a lot more steps)

#include
#include
main(argc, argv)
int argc;
char *argv[];
{
char salt[3];
char *EncryptedPasswd;
int CheckRand;
int Fixup;
int SeedChar;

printf("\nUsage: pw \n\n");
srand(time(NULL));
for ( SeedChar = 0; SeedChar <= 1; SeedChar++) {
CheckRand = 46 + rand() % 76; /* random number from 46 to 122 */
Fixup = 7 + rand() % 13; /* random number from 7 to 20 */
salt[SeedChar] = toascii(((CheckRand >= 58 && CheckRand <= 64) ||
(CheckRand >= 91 && CheckRand <= 96) ? CheckRand + Fixup : CheckRand));
}
EncryptedPasswd=crypt(argv[1], salt);
printf("\nRequested pw= %s, Automatic Seed= %s, encrypted pw= %s\n",
argv[1], salt, EncryptedPasswd);
}


Bill Hassell, sysadmin
Steven Gillard_2
Honored Contributor

Re: automating passwd in script

Just to give you another option... the attached C program correctly adds a new entry to /etc/passwd (ie it first locks /etc/.pwd.lock to prevent concurrent updates). It allows you to specify the everything except the gecos field on the command line. The uid is automatically selected as the highest current uid + 1.

It requires the ANSI C or GNU compiler - see the comments for more info.

Cheers,
Steve