Operating System - HP-UX
1834149 Members
2194 Online
110064 Solutions
New Discussion

How to change passwd with in the scrip with out asking in the terminal

 
SOLVED
Go to solution
chakribobby
Advisor

How to change passwd with in the scrip with out asking in the terminal

Hi
I need to change the password for the user with in the scrip(with in the scrip i have given the password)
While running that scrip it should not ask for password
That scrip is run by root
Thanks in advance
6 REPLIES 6
Arturo Galbiati
Esteemed Contributor

Re: How to change passwd with in the scrip with out asking in the terminal

Hi,
please, can you post your original script used to given teh passwords?
This may help in fix your problem.
Rgds,
Art
chakribobby
Advisor

Re: How to change passwd with in the scrip with out asking in the terminal

thanks for you reply
here i am giving you the snap shot


New_passwd=xzy #is the new password
passwd user

with in the scrip If we use above command it will ask for passwd in the terminal when we run that script


New_passwd=xzy #is the new password
passwd user < New_passwd

what I need is it should not ask for password when I run it
VK2COT
Honored Contributor

Re: How to change passwd with in the scrip with out asking in the terminal

Hello,

Check this:

http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt

You will easily see commands you can use to change user's password in HPUX, Solaris, AIX, Linux, and Tru64 in a script :)

Cheers,

VK2COT
VK2COT - Dusan Baljevic
chakribobby
Advisor

Re: How to change passwd with in the scrip with out asking in the terminal

Thanks for you reply
It is more complex
Can you given me a small example
chakribobby
Advisor

Re: How to change passwd with in the scrip with out asking in the terminal

in shell script
VK2COT
Honored Contributor
Solution

Re: How to change passwd with in the scrip with out asking in the terminal

It is one-liner:

/usr/sam/lbin/usermod.sam -p passwordhash

Your problem is how to find out the
passwordhash. It is the encrypted password
string (the one you see in /etc/passwd or
/etc/shadow...)

Normally, you would have to use some kind
of random password generators. That is
where Perl and Expect scripts, and other tools come handy.

If you already have a good passwordhash
string, then you are OK.

The alternative is to use GNU useradd with
flag "-p":

You get an already-encrypted passwd, and use
the -p option, along with
the other options can automate this process:

useradd -d /home/user1 -g users -m -k -p passwordhash -s /bin/ksh

So, in the end, simple lines for your script:

#!/bin/sh
PATH=/usr/sbin:/sbin:/bin:/usr/sam/lbin; export PATH

MYSALT="somestring"
MYPASS="whateverpassword"

MYENCPASS=`perl -e 'print crypt("mypassword", "salt"),"\n"'`

usermod.sam -p $MYENCPASS username

exit 0

It is a trivial exercise to add more features
in the script (like error checking, or adding support for command-line arguiments).

Please do not forget to assign points if you find any advice in ITRC forums useful.

Cheers,

VK2COT
VK2COT - Dusan Baljevic