useradd: ERROR: invalid syntax


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting useradd: ERROR: invalid syntax
# 1  
Old 08-18-2011
useradd: ERROR: invalid syntax

Hello - I have the below script
Code:
syncToken=None;\
forceDeleteUserHome=true;\
nisPwdDir=/etc;\
mirrorFilesLocation=/etc/connector_mirror_files;\
removeHomeDirContents=true;\
shadow=false;\
connectorPrompt=#;\
nisBuildDirectory=/var/yp;\
PGROUP=nogroup;\
COMMENTS='Comments\\ with\\ space';\
__NAME__=manju128;\
USER_SHELL=/bin/sh;\
HOME_DIR='/home/dir\\ with\\ space';\
if [ ! -z "$__UID__" ] ;\
then    __NAME__=$__UID__;\
else    __NAME__=$__NAME__;\
fi;\
if id $__NAME__ > /dev/null 2>&1 ;\
then      echo "User already exists";\
else     globalVar="true";\
    homedir="";\
        echo HOME_DIR=$HOME_DIR;    if [ ! -z "$HOME_DIR" ] ;\
then         homedir=$HOME_DIR;\
                echo inside if homedir=$homedir;\
    else         if [ ! -z "$defaultHomeBaseDir" ] ;\
then             homedir=$defaultHomeBaseDir;\
                        echo inside else homedir=$homedir;\
        fi;\
    fi;\
    if [ ! -z "$homedir" ] ;\
then         command="$command -d $homedir/$__NAME__";\
                echo inside 2 if command=$command;\
    fi;\
    if [ ! -z "$CREATE_HOME_DIR" ] && [ "$CREATE_HOME_DIR" = "true" ];\
then         command="$command -m";\
        if [ ! -z "$SKEL_DIR" ] ;\
then             command="$command -k $SKEL_DIR";\
        fi;\
    fi;\
        echo COMMENTS=$COMMENTS;\
    if [ ! -z "$COMMENTS" ] ;\
then         command="$command -c $COMMENTS";\
    fi;\
        echo after comments if COMMAND=$COMMAND;    if [ ! -z "$PGROUP" ] ;\
then         grp=$PGROUP;\
    else         if [ ! -z "$defaultPriGroup" ];\
then             grp=$defaultPriGroup;\
        fi;\
    fi;\
    if [ ! -z "$grp" ] ;\
then         command="$command -g $grp";\
    fi;\
    if [ ! -z "$SECONDARYGROUP" ] ;\
then         command="$command -G $SECONDARYGROUP";\
    fi;\
    if [ ! -z "$USER_SHELL" ] ;\
then         command="$command -s $USER_SHELL";\
    else         if [ ! -z "$defaultShell" ] ;\
then             command="$command -s $defaultShell";\
        fi;\
    fi;\
    if [ ! -z "$EXP_DATE" ] ;\
then         command="$command -e $EXP_DATE";\
    fi;\
    if [ ! -z "$INACTIVE" ] && [  "$INACTIVE" -gt 0 ];\
        then command="$command -f $INACTIVE";\
    fi;\
    if [ ! -z "$USID" ] && [  "$USID" -gt 0 ] ;\
 then         command="$command -u $USID";\
        if [ ! -z "$UNIQUE_USID" ] && [  "$UNIQUE_USID" = "false" ] ;\
then             command="$command -o";\
        fi;\
    fi;\
        echo ">>>>Command = $command <<<<";    if [ "$globalVar" = "true" ];\
then         echo "useradd $command $__NAME__";
                         command="useradd $command $__NAME__";
                         echo Final command is $command;
                     $command;
        [ $? -eq 0 ] && echo "SUCCESS";\
    fi;\
fi;\
unset command globalVar __NAME__ COMMENTS AUTHORIZATION PROFILE ROLE HOME_DIR;\
unset USER_SHELL USID PGROUP grp SKEL_DIR EXP_DATE UNIQUE_USID homedir defaultShell;\
unset defaultPriGroup defaultHomeBaseDir INACTIVE CREATE_HOME_DIR SECONDARYGROUP;

If you see i am printing the command just before executing saying "Final command is.. "
But this script fails saying invalid syntax error, however i execute the command (echoed) directly - it creates the user fine.

Please help..!

Moderator's Comments:
Mod Comment Please use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.

Last edited by zaxxon; 08-18-2011 at 04:36 AM.. Reason: code tags
# 2  
Old 08-18-2011
Which shell are you using? If you are using a shell, those ;\ at the end of each line should not be needed.
What exact error do you get? Maybe add set -x in the 1st line for debugging to see where you get problems.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-18-2011
set -x is sexy.

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Invalid null command error

Hi, I have this script which gives me output as Invalid null command set recent_file=`grep '^-.*xlsx$' $FTP_LOG |\ sed -e 's/Jan/1/g' \ -e 's/Feb/2/g' \ -e 's/Mar/3/g' \ -e... (6 Replies)
Discussion started by: juzz4fun
6 Replies

2. Shell Programming and Scripting

sed error: invalid reference

Hello all, I am using sed to parse a particular part of a string and am having problems. I am getting the following error: sed: -e expression #1, char 28: invalid reference \1 on `s' command's RHS Here is the code I am using: echo "Alarm SET:" echo "" echo "Date: " $DATE echo... (4 Replies)
Discussion started by: dlundwall
4 Replies

3. Solaris

useradd: ERROR: Path must not start with '/home/'.

root@solaris11express:/home# useradd -d /home/oracle oracle UX: useradd: ERROR: Path must not start with '/home/'. and the user oracle is not being created... (2 Replies)
Discussion started by: kompcouk
2 Replies

4. Solaris

Error in useradd cmd

Thanks to explain how to resolve this error: useradd -d /export/home/kish -m -s /bin/ksh -c "kkalyan" UX: useradd: ERROR: invalid syntax. usage: useradd | -g group | -G group...] | -d dir | -s shell | -c comment | -m | -f inactive | -e expire | -A... (4 Replies)
Discussion started by: kkalyan
4 Replies

5. HP-UX

ERROR[55]: Invalid or inaccessible system ID

Hi all, I was changing a motherboard which has the MP console down on an rx4640. I am receiving the following error: ERROR: Invalid or inaccessible system ID(s) then it takes me to the EFI where it doesn't boot from the primary path. I contacted a colleague who already replaced two... (0 Replies)
Discussion started by: MazenH
0 Replies

6. UNIX for Dummies Questions & Answers

syntax error: invalid arithmetic operator

hi, i have a bash script that i want to receive a a string from another bash file. But because the string has a dot in the middle it gives me an error. The error is in this line: let valor=$1 and the value passed is rules.txt the error is: let: valor=rules.txt: syntax error: invalid... (2 Replies)
Discussion started by: limadario
2 Replies

7. UNIX for Dummies Questions & Answers

useradd on bash gives me error

Hi everyone, On executing the following command i always get this error >useradd -c 'none' -s # -u 5001 -f 100 -m -g 'wheel' -d /home/phildpop useradd: option requires an argument -- s Try `useradd --help' or `useradd --usage' for more information. (1 Reply)
Discussion started by: phildpop
1 Replies

8. Shell Programming and Scripting

01.30 Invalid shell error

Hi, I am getting the error 01.30 Invalid shell error I am running the bash shell script in the korn login shell. I have mentioned the #!/bin/bash statement in the my script but not sure why it is giving this error to me.. (4 Replies)
Discussion started by: mr_harish80
4 Replies

9. Solaris

useradd giving error in solaris 10

Hi, I have installed Solaris 10 in my PC and now installing Oracle10, but while adding a user i am getting following error: useradd -g oinstall -G dba -d /export/home/oracle oracle UX: useradd: ERROR: Inconsistent password files. See pwconv(1M). I have tried pwconv command,... (4 Replies)
Discussion started by: amitanshu.verma
4 Replies

10. UNIX for Advanced & Expert Users

Useradd Error

Seems that I'm having issues adding a user on our AIX Version 5.1 server. When I added the user dh I get the following error: # useradd dh 3004-721 Could not create user. 3004-703 Check "/usr/lib/security/mkuser.sys" file. 3004-687 User "dh" does not exist. The /etc/passwd gets the... (1 Reply)
Discussion started by: Nico
1 Replies
Login or Register to Ask a Question