Passing variables to mkuser


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Passing variables to mkuser
# 1  
Old 04-28-2015
Passing variables to mkuser

In a ksh, I'm attempting to pass my string of arguments to the mkuser command in a variable as follows...

Code:
   cmd="pgrp=ACRGENU groups=ACRGENU home=/home/${USERID} shell=/usr/bin/ksh"
   cmd=$cmd" gecos='${USERNAME}' login=true su=false rlogin=true daemon=true"
   cmd=$cmd" admin=false sugroups=ALL tpath=nosak ttys=ALL expires=0 auth1=SYSTEM"
   cmd=$cmd" auth2=NONE umask=22 registry=files SYSTEM=compat loginretries=5"
   cmd=$cmd" pwdwarntime=5 account_locked=false minage=0 maxage=12 maxexpired=1"
   cmd=$cmd" minalpha=5 minother=2 mindiff=3 maxrepeats=3 minlen=8 histexpire=26"
   cmd=$cmd" histsize=10 fsize=-1 cpu=-1 data=-1 stack=-1 core=-1 rss=-1 nofiles=-1"
   cmd=$cmd" stack_hard=-1 unsuccessful_login_count=0 ${USERID}"
   echo "Executing mkuser command..."
   mkuser $cmd

And am getting the following error...
Code:
Usage: mkuser [-R load_module] [-a] "attr=value" ... newuser

I'm sure this is an extremely newbie question, but what should I be doing to my "mkuser $cmd" line to get it to pick up the variables correctly?

Thanks!
A mainframe dinosaur in a strange land.
# 2  
Old 04-28-2015
Is USERID defined? Try putting echo ${cmd} in the script right before mkuser and take a look at the string.
This User Gave Thanks to blackrageous For This Post:
# 3  
Old 04-28-2015
Thanks for the reply blackrageous! Stuck an echo in and USERID looks good. Also echo'ed the return code ($?) afterwards (RC=22), but Uncle Google isn't telling me much on it...

Code:
Executing mkuser command...
pgrp=ACRGENU groups=ACRGENU home=/home/lbubba shell=/usr/bin/ksh gecos='Bubba Jones' login=true su=false rlogin=true daemon=true admin=false sugroups=ALL tpath=nosak ttys=ALL expires=0 auth1=SYSTEM auth2=NONE umask=22 registry=files SYSTEM=compat loginretries=5 pwdwarntime=5 account_locked=false minage=0 maxage=12 maxexpired=1 minalpha=5 minother=2 mindiff=3 maxrepeats=3 minlen=8 histexpire=26 histsize=10 fsize=-1 cpu=-1 data=-1 stack=-1 core=-1 rss=-1 nofiles=-1 stack_hard=-1 unsuccessful_login_count=0 lbubba
Usage: mkuser [-R load_module] [-a] "attr=value" ... newuser
ERROR: MKUSER command failed with return code 22

---------- Post updated at 03:53 PM ---------- Previous update was at 03:26 PM ----------

A little more info... I've found the issue seems to be the single quotes around the "gecos=" attribute. If exclude the
Code:
gecos='${USERNAME}'

attribute, then it works. However, if I cut/paste the echo output (including the gecos attribute) behind a mkuser on the command line, it runs. For some reason, it doesn't like the single quotes inside the variable.
# 4  
Old 04-29-2015
I'm irritated that your 'reused' $cmd' is outside the quotes.
You could try (instead):
Code:
cmd+=" new values"

This will preserve cmd's previous values, and append the 'new values' at their end.

Regarding the single quotes, you could use them if you escape them, better yet, escape double quotes when passing values with spaces to options. Of no space (or other special char) is within the value, then you dont have to put it in quotes (though, still should).

Hope this helps
# 5  
Old 04-29-2015
I finally stumbled onto the answer, if not the reason... Seems when passing a single quote delimited value to mkuser (or chuser) via a variable, the entire attribute must be surrounded by double quotes... and it doesn't like it with multiple attributes....

These do not work...
Code:
$cmd="pgrp=AGROUP groups=AGROUP gecos='John Doe'"
mkuser $cmd $USERID

Code:
$cmd='pgrp=AGROUP groups=AGROUP "gecos=''John Doe''" '
mkuser $cmd $USERID

But this DOES work...
Code:
$cmd="pgrp=AGROUP groups=AGROUP"
mkuser $cmd $USERID
$cmd="gecos='John Doe'"
chuser "$cmd" $USERID

Thanks all for the replies!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

2. Shell Programming and Scripting

Passing Variables

I have below data: DAY1=10202013 I am trying below but not getting the desired output: COUNT=1 DATE=DAY$COUNT echo "Date is $DATE" However output I am getting is: Date is DAY1 I wanted the output as: Date is 10202013 I tried following as well: DAY1=10202013 COUNT=1... (3 Replies)
Discussion started by: rockyr1985
3 Replies

3. Shell Programming and Scripting

Passing variables and setting them

So I'm writing a script to generate pairwise scores for how similar two strings are, and while I've been able to get it to work on a single script, I've been unable to iterate it. So suppose I have a file thus 1234567890 1234567890 1234567899 first I need to assign two lines, by their... (3 Replies)
Discussion started by: viored
3 Replies

4. Shell Programming and Scripting

Passing variables between sub-scripts

I have written a program for some data analysis. It is gettin long. I would like to restructure it so that i can have a master file which controls multiple subscripts in order to make it easier to understand. I need to be able to define variables in the master script which are used by all three... (2 Replies)
Discussion started by: carlr
2 Replies

5. Shell Programming and Scripting

Passing two variables to function

HI ,I am a new in Bash and ,I dont know how to pass a second parameter to this fuction,if the name of the passed argument is num works fine,but if I try to pass secondNum,dont recognized it thanks function check() { if(($(echo ${#num}) == 0 )) then echo No arguments passed.Try... (6 Replies)
Discussion started by: lio123
6 Replies

6. Shell Programming and Scripting

Passing 2 variables

Hi All, I need to pass 2 variables name 'vamskt' and 'vamsi'. Here is my question: delete from gpi.usergroup where usg_user_id in ('vamskt'); delete from gpi.userroles where uro_user_id in ('vamskt'); delete from gpi.user where usr_id in ('vamskt'); insert into gpi.user... (3 Replies)
Discussion started by: tvamsikiran
3 Replies

7. Shell Programming and Scripting

Passing variables to sed

Hi Folks, How can I make the following to work from a korn shell? old="OLDSTRING" new="NEWSTRING" file="myfile.txt" sed -n 's/$old/$new/gp' $file Thanks in advance rogers42 (3 Replies)
Discussion started by: rogers42
3 Replies

8. Shell Programming and Scripting

nawk - Passing variables

Hi, I am passing the varibale using nawk -v to search the pattern from the file. But this variable is not accepting. I couldn't get the crrect output. Help me regarding..... nawk -v PGMNAME="$prog" ' { $0 ~ /PGMNAME/ { .................. ................. ... (3 Replies)
Discussion started by: sharif
3 Replies

9. Shell Programming and Scripting

passing variables

Hi, Is there any way to pass variable to a sed script.For awk we have -v option.like that do we have any way to pass variable to a sed script from a awk script or from normal script? Thanx, sounder (1 Reply)
Discussion started by: sounder123
1 Replies

10. Shell Programming and Scripting

Passing Variables to AWK

Does anybody have an explanation for the following: The following scripts runs fine on IRIX64 6.5 but has bugs on Solaris 8. #! /bin/sh echo run only on an SGI machine echo type in linenumber read j echo value read value awk -f rmspass2 level=$value $j'step1.mlf' When the script is... (5 Replies)
Discussion started by: AreaMan
5 Replies
Login or Register to Ask a Question