LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Solaris / OpenSolaris (https://www.linuxquestions.org/questions/solaris-opensolaris-20/)
-   -   set passwords in a script in solaris 9 and return (https://www.linuxquestions.org/questions/solaris-opensolaris-20/set-passwords-in-a-script-in-solaris-9-and-return-4175434240/)

slufoot80 10-26-2012 02:10 PM

set passwords in a script in solaris 9 and return
 
I have a script that adds a user to the solaris 9 system

I also have a random password generator so I can pass the password to the command but someone needs to hit return twice to set it, I want the script to set it for me so I don't have to hit return. As it is now after I add the user I set the password manually I don't want to do that I want the script to do that for me, How do I make this work

archShade 10-26-2012 03:14 PM

What do you want the script to do?

Many cli programs that require a password have the option of passing the password as a parameter. For example useradd takes the -p flag followed by a string to add the password. If this is used you will not need to press return twice when the user account is set up.

HTH

MensaWater 10-26-2012 03:14 PM

I haven't done it on Solaris 9 but generally whenever you have an interactive program that waits for response to prompts the best thing to use is "expect".

I found this thread about expect for Solaris 9.
http://compgroups.net/comp.unix.sola...all-sol/333544

slufoot80 10-30-2012 02:33 PM

send variable to expect
 
I have a user add script to add a user to Solaris 9 it does everything except set the password, I have a password generator in my script I want to set the generator to a variable and pass the variable to expect so I can set the password when adding the user.

MensaWater 10-31-2012 09:48 AM

Within expect you can use command line arguments passed in so for example using first argument from command line (e.g. same thing as $1 in a shell script):

set newpw [lrange $argv 0 0]
whaterver...
send $newpw

linosaurusroot 11-02-2012 11:24 AM

You could create the hash yourself and then append a line (all 7 fields) to /etc/passwd . After all accounts are added run pwconv . If doing this I'd set the "must change at next login" option in the hash to force a change to the new and better hashes available in Solaris 9.

slufoot80 11-05-2012 09:58 AM

from password generator to expect for Solaris
 
what I want to do is this I have a password generator as seen below which is in my script. this works for linux because linux has the "-p" option to pass the password too during the run of the useradd command, but Solaris doesn't as seen below for linux which is actually 2 stages

Code:

password=`</dev/urandom tr -dc A-Za-z0-9 | head -c8`

pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) # passing the password entered

"useradd -u $uid -p $pass -c "$comment $commentstatic" -d $homedir -s $shell $username"



then take the "password" variable and send that to expect so I don't have to enter it manually.


All times are GMT -5. The time now is 06:15 AM.