How to create a user account from a text file input

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Need to create a bash script to create a username from a file which contains below (username home directory full name)



drs /home/drs Paranas Theruwalan



My script:



!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)

USER_FULLNAME=$(cat file.txt | cut -d: -f2)

useradd -m ($USERNAME) -c ($USER_FULNAME)


I getting invalid username error.










share|improve this question























  • Related: How to add users from data in a text file
    – steeldriver
    Aug 15 at 10:09














up vote
0
down vote

favorite












Need to create a bash script to create a username from a file which contains below (username home directory full name)



drs /home/drs Paranas Theruwalan



My script:



!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)

USER_FULLNAME=$(cat file.txt | cut -d: -f2)

useradd -m ($USERNAME) -c ($USER_FULNAME)


I getting invalid username error.










share|improve this question























  • Related: How to add users from data in a text file
    – steeldriver
    Aug 15 at 10:09












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Need to create a bash script to create a username from a file which contains below (username home directory full name)



drs /home/drs Paranas Theruwalan



My script:



!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)

USER_FULLNAME=$(cat file.txt | cut -d: -f2)

useradd -m ($USERNAME) -c ($USER_FULNAME)


I getting invalid username error.










share|improve this question















Need to create a bash script to create a username from a file which contains below (username home directory full name)



drs /home/drs Paranas Theruwalan



My script:



!#/bin/bash
#call data from file
file="file.txt"
USERNAME=$(cat file.txt | cut -d: -f1)

USER_FULLNAME=$(cat file.txt | cut -d: -f2)

useradd -m ($USERNAME) -c ($USER_FULNAME)


I getting invalid username error.







accounts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 15 at 9:51









msp9011

3,46643862




3,46643862










asked Aug 15 at 9:23









Suresh Silva

1




1











  • Related: How to add users from data in a text file
    – steeldriver
    Aug 15 at 10:09
















  • Related: How to add users from data in a text file
    – steeldriver
    Aug 15 at 10:09















Related: How to add users from data in a text file
– steeldriver
Aug 15 at 10:09




Related: How to add users from data in a text file
– steeldriver
Aug 15 at 10:09










3 Answers
3






active

oldest

votes

















up vote
0
down vote













First you should remove the () for using variables:
useradd -m $USERNAME -c $USER_FULNAME



Second check the output of username, maybe it includes invalid characters.






share|improve this answer





























    up vote
    0
    down vote













    Here you go:



    #!/bin/bash
    #call data from file
    FILE="file.txt"
    USERNAME=$(cut -d " " -f 1 $FILE)
    USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
    useradd -m -c "$USER_FULLNAME" "$USERNAME"





    share|improve this answer



























      up vote
      0
      down vote













      What are your separators, space or colon? You example suggests space, your code suggests colon.



      You can do that in bash.



      #!/bin/bash
      file="file.txt"
      while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
      useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
      done < "$file"


      This example assumes as input a file with lines like



      drs:/home/drs:Paranas Theruwalan





      share|improve this answer




















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462708%2fhow-to-create-a-user-account-from-a-text-file-input%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote













        First you should remove the () for using variables:
        useradd -m $USERNAME -c $USER_FULNAME



        Second check the output of username, maybe it includes invalid characters.






        share|improve this answer


























          up vote
          0
          down vote













          First you should remove the () for using variables:
          useradd -m $USERNAME -c $USER_FULNAME



          Second check the output of username, maybe it includes invalid characters.






          share|improve this answer
























            up vote
            0
            down vote










            up vote
            0
            down vote









            First you should remove the () for using variables:
            useradd -m $USERNAME -c $USER_FULNAME



            Second check the output of username, maybe it includes invalid characters.






            share|improve this answer














            First you should remove the () for using variables:
            useradd -m $USERNAME -c $USER_FULNAME



            Second check the output of username, maybe it includes invalid characters.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 15 at 9:48

























            answered Aug 15 at 9:38









            Amirk

            11




            11






















                up vote
                0
                down vote













                Here you go:



                #!/bin/bash
                #call data from file
                FILE="file.txt"
                USERNAME=$(cut -d " " -f 1 $FILE)
                USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
                useradd -m -c "$USER_FULLNAME" "$USERNAME"





                share|improve this answer
























                  up vote
                  0
                  down vote













                  Here you go:



                  #!/bin/bash
                  #call data from file
                  FILE="file.txt"
                  USERNAME=$(cut -d " " -f 1 $FILE)
                  USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
                  useradd -m -c "$USER_FULLNAME" "$USERNAME"





                  share|improve this answer






















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Here you go:



                    #!/bin/bash
                    #call data from file
                    FILE="file.txt"
                    USERNAME=$(cut -d " " -f 1 $FILE)
                    USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
                    useradd -m -c "$USER_FULLNAME" "$USERNAME"





                    share|improve this answer












                    Here you go:



                    #!/bin/bash
                    #call data from file
                    FILE="file.txt"
                    USERNAME=$(cut -d " " -f 1 $FILE)
                    USER_FULLNAME=$(cut -d " " -f 3,4 $FILE)
                    useradd -m -c "$USER_FULLNAME" "$USERNAME"






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 15 at 10:09









                    mikst

                    967




                    967




















                        up vote
                        0
                        down vote













                        What are your separators, space or colon? You example suggests space, your code suggests colon.



                        You can do that in bash.



                        #!/bin/bash
                        file="file.txt"
                        while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
                        useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
                        done < "$file"


                        This example assumes as input a file with lines like



                        drs:/home/drs:Paranas Theruwalan





                        share|improve this answer
























                          up vote
                          0
                          down vote













                          What are your separators, space or colon? You example suggests space, your code suggests colon.



                          You can do that in bash.



                          #!/bin/bash
                          file="file.txt"
                          while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
                          useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
                          done < "$file"


                          This example assumes as input a file with lines like



                          drs:/home/drs:Paranas Theruwalan





                          share|improve this answer






















                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            What are your separators, space or colon? You example suggests space, your code suggests colon.



                            You can do that in bash.



                            #!/bin/bash
                            file="file.txt"
                            while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
                            useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
                            done < "$file"


                            This example assumes as input a file with lines like



                            drs:/home/drs:Paranas Theruwalan





                            share|improve this answer












                            What are your separators, space or colon? You example suggests space, your code suggests colon.



                            You can do that in bash.



                            #!/bin/bash
                            file="file.txt"
                            while IFS=: read USERNAME USER_HOME USER_FULLNAME; do
                            useradd -m -c "$USER_FULLNAME" -d "$USER_HOME" "$USERNAME"
                            done < "$file"


                            This example assumes as input a file with lines like



                            drs:/home/drs:Paranas Theruwalan






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Aug 15 at 10:19









                            RalfFriedl

                            3,7001523




                            3,7001523



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462708%2fhow-to-create-a-user-account-from-a-text-file-input%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?