Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jan 2002 00:09:37 -0600
From:      "Bob Giesen" <BobGiesen@earthlink.net>
To:        "Joe & Fhe Barbish" <barbish@a1poweruser.com>, "FBSD Questions" <questions@FreeBSD.ORG>
Subject:   Re: pw in script to create new user.
Message-ID:  <004b01c1a30b$5fcb20c0$328dfea9@pegasus>
References:  <LPBBIGIAAKKEOEJOLEGOKEFHCNAA.barbish@a1poweruser.com>

next in thread | previous in thread | raw e-mail | index | archive | help
----- Original Message -----
From: "Joe & Fhe Barbish" <barbish@a1poweruser.com>
To: "FBSD Questions" <questions@FreeBSD.ORG>
Sent: Monday, January 21, 2002 10:52 PM
Subject: pw in script to create new user.


> I have sh script with this in it
> Pw adduser tom -m -c bkup manager -o
> The /etc/pw.conf has all the defaults, one is to
> make the password the same as the userid.
> The -o option will take input from keyboard for the
> Password but this is a canned script so I need to
> Some how pass the password value to the pw command -0 option.
>
> How can I configure the script to hold the password value
> for that userid so when the pw adduser command is executed
> the correct password gets used in creating the user?

   Three thoughts:
1) Does pw offer no other way of providing the password, other than via
stdin (keyboard)?
2) Putting unencrypted passwords into a text file (such as your script) does
present something of a security risk.
3) If the answer to (1) is no and (2) doesn't faze you, you can redirect
stdin within the script.  I am not familiar with pw (perhaps because I'm
running v3.2), so I'll expand on your example command for adding tom:

Pw adduser tom -m -c bkup manager -o << EOF
tomspassword
EOF

   The first line's "<< EOF" tells sh to take the expected stdin input from
the following lines, up to the first line that BEGINS with "EOF."  So, just
put tom's password on the following line and then EOF on the very next line.
   Two points worth mentioning:
1) My choice of "EOF" was arbitrary.  You may use EOP, EOI, XYZ, SILLY, or
whatever you like, so long as you use exactly the same string to signal the
end of input redirection.
2) EOF (or EOP, SILLY, or whatever you use) MUST BEGIN the line to signal
the end of redirection.  Any space (or other character) before the ending
EOF will mess up your script (which, since you're operating as root, has the
potential to make things interesting, to say the least).  (Exception: you
may precede the finishing string (EOF, or whatever) with a tab IF YOU USE
"<<-" instead of "<<" for the redirection on the first line.  E.g.:

Pw adduser tom -m -c bkup manager -o <<- EOF
    tomspassword
    EOF

   My mail client turned the tabs to spaces; there should be tabs before
"tomspassword" and the final "EOF" here.  Sometimes, the <<- & tab
functionality helps to make a more readable script.
   Hope this helps...
- Bob

> A example of the script  pw command would be great.
>
> Thanks
> Joe
>
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?004b01c1a30b$5fcb20c0$328dfea9>