From owner-freebsd-questions Tue Jan 22 11:14:47 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mail.mango-bay.com (mail.mango-bay.com [208.206.15.12]) by hub.freebsd.org (Postfix) with ESMTP id B0E8537B402 for ; Tue, 22 Jan 2002 11:14:39 -0800 (PST) Received: from gateway ([63.70.155.108]) by mail.mango-bay.com (Post.Office MTA v3.5.3 release 223 ID# 0-52377U2500L250S0V35) with SMTP id com; Tue, 22 Jan 2002 14:17:50 -0500 From: "Joe & Fhe Barbish" To: "Bob Giesen" Cc: "FBSD Questions" Subject: RE: pw in script to create new user. Date: Tue, 22 Jan 2002 14:14:33 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 In-Reply-To: <004b01c1a30b$5fcb20c0$328dfea9@pegasus> Importance: Normal Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG To all who responded I want to say thanks for your input. I have gotten my script to work. Now for the archives I am summarizing how the pw command works. When FBSD is installed the PW command does not have it's pw.conf option file. Pw stills works but you have no idea what the defaults are and the command line gets full using the pw flags. The first thing you should do if you want to use the pw command to add users is to create the pw.conf file, do this by entering pw -D this will create the /etc/pw.conf file. The comments in the file are self explanatory. I added the default group and the additional groups. pw -D = create /etc/pw.conf file pw adduser tom -m -c tom brown = tom =userid -m = create home directory -c full name field pw deluser tom -r = delete user tom -r = remove home directory pw showuser tom = display this users entry in password file pw showuser tom -P = display password info in human readable form pw showuser -a = display all entries in password file The pw command can also be used for groups pw addgroup networking pw showgroup networking The pw command can also change settings in the userid password file. My /etc/pw.conf looks like this # # /etc/pw.conf - user/group configuration defaults # created 01/20/2002 by Joe Barbish # Password for new users? no=nologin yes=loginid none=blank random=random defaultpasswd = "yes" # Reuse gaps in uid sequence? (yes or no) reuseuids = "yes" # Reuse gaps in gid sequence? (yes or no) reusegids = "yes" # Path to the NIS passwd file (blank or 'no' for none) nispasswd = # Obtain default dotfiles from this directory skeleton = "/usr/share/skel/" # Mail this file to new user (/etc/newuser.msg or no) newmail = "no" # Log add/change/remove information in this file logfile = "/var/log/userlog" # Root directory in which $HOME directory is created home = "/home" # Colon separated list of directories containing valid shells shellpath = "/bin" # Comma separated list of available shells (without paths) shells = "sh","csh","tcsh" # Default shell (without path) defaultshell = "sh" # Default group (leave blank for new group per user) defaultgroup = "network" # Extra groups for new users extragroups = "wheel" # Default login class for new users defaultclass = "" # Range of valid default user ids minuid = 1000 maxuid = 32000 # Range of valid default group ids mingid = 1000 maxgid = 32000 # Days after which account expires (0=disabled) expire_days = 0 # Days after which password expires (0=disabled) password_days = 0 ###################################################### The script that the folks here helped me with. #! /bin/sh pw adduser tom -m -c testing -h 0 <<- EOD water EOD # water is the password used for tom -----Original Message----- From: owner-freebsd-questions@FreeBSD.ORG [mailto:owner-freebsd-questions@FreeBSD.ORG]On Behalf Of Bob Giesen Sent: Tuesday, January 22, 2002 1:10 AM To: Joe & Fhe Barbish; FBSD Questions Subject: Re: pw in script to create new user. ----- Original Message ----- From: "Joe & Fhe Barbish" To: "FBSD Questions" 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 -h 0 << 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 -h 0 <<- 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message