|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Create new user account and password in shell script
I am trying to create a shell script that will:
I can do 1 (using the id command) and 2 (using mkgroup or groupadd and useradd commands), but setting the password is where I am having problems. I have got it to work on Linux by redirecting input to the passwd command but I can not find how to get the same functionality to work on AIX and Solaris. This is what I have so far: Code:
PLATFORM=`uname`
id $NEW_USER_ID > /dev/null 2>&1
if [ "$?" != "0" ]
then
echo "$NEW_USER_ID user does not exist. Attempting to create user and group"
if [ "$PLATFORM" = "AIX" ]
then
mkgroup $NEW_GROUP
else
groupadd $NEW_GROUP
fi
if [ "$?" != "0" ]
then
echo "Failed to create group"
fi
useradd -g $NEW_GROUP -s /usr/bin/ksh $NEW_USER_ID
if [ "$?" != "0" ]
then
echo "Failed to create $NEW_USER_ID user"
fi
if [ "$PLATFORM" = "Linux" ]
then
passwd --stdin $NEW_USER_ID <<EOF
$NEW_PASSWD
$NEW_PASSWD
EOF
if [ "$?" != "0" ]
then
echo "Failed to set $NEW_USER_ID password"
fi
fi
fiI've searched the forums and found some similar postings but nothing seems to answer exactly what I'm looking for. Some additional information that might preempt some questions:
Thanks in advance for any help or pointers that anyone can provide. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
What was done in case of Solaris what were the errors ?
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
On Solaris I have tried: 1) redirecting the input as follows: Code:
passwd $NEW_USER_ID <<EOF > $NEW_PASSWD > $NEW_PASSWD > EOF but I get prompted to enter the password interactively: New Password:2) putting the passwords into a file Code:
echo $NEW_PASSWD >> tempfile echo $NEW_PASSWD >> tempfile then tried to redirect the contents of that file into the passwd command: Code:
passwd $NEW_USER_ID < `cat tempfile` from which I get the error: ksh: $NEW_PASSWD^J$NEW_PASSWD: cannot open(the error actually shows the real password not the environment variable) or: Code:
passwd $NEW_USER_ID < tempfile but again I get prompted to enter the password interactively: New Password:3) write a mini shell script: Code:
sleep 1 echo $NEW_PASSWD sleep 1 echo $NEW_PASSWD then tried to execute that script and pipe the output to the passwd command: Code:
./script | passwd $NEW_USER_ID but again I get prompted to enter the password interactively: New Password:So, it looks to me like my attempts to redirect stdin to the passwd command are failing but I don't know any other way to do it. |
|
#4
|
||||
|
||||
|
Hi.
There is no way to do what you want on Solaris using the passwd command. You could download and compile a tool like chpasswd, but you don't want to do that. One option is to change the password on one server, and then use information in the shadow file to update the other servers. For AIX, the tool chpasswd should already be available. It's easy enough to use - check the man page. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Thanks scottn. Appreciate the answer. I'll use chpasswd on AIX and think up an alternative solution on Solaris.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need a Shell script to create Multiple User Accounts | rksubash | Shell Programming and Scripting | 1 | 06-14-2008 08:15 AM |
| script to create multiple instances of a user account across LPAR's | kcampbell | Filesystems, Disks and Memory | 1 | 10-19-2006 10:42 PM |
| How to create a new ftp user account with limited access..? | Jeremy3 | Solaris | 6 | 09-01-2006 05:52 AM |
| how can I change user name and password , of account ? | umen | Solaris | 5 | 12-22-2005 06:10 PM |
| create or modify user account to have same access as root | xadamz23 | UNIX for Dummies Questions & Answers | 6 | 08-07-2003 07:59 PM |
|
|