Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
I have write a script to add a new user account in linux system, but my scipt didnt run good. I just want to run the command add new user ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7

    Creating new user account in Linux


    I have write a script to add a new user account in linux system, but my scipt didnt run good. I just want to run the command add new user in perl programming but I cannot:
    here is one part of my sript:
    #!/usr/bin/perl
    $user = <STDIN>;
    system("useradd $user -d/home/myfolder/$user -g GROUP");

    When I run this script it will report:
    sh: line 1: -d/home/myfolder/user : No such file or directory
    sh: line 2: -g: command not found

    can anyone help me out with this?
    thank you very much
    KHOA

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,882
    I'm no expert on PERL, but cant you just use the regular 'useradd' script that comes with your distro?
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7
    Yes, me too, I just begin to study this subject .
    Thanks for reply, Roxoff !
    Because the question require me after create a new account I have to write some infomation to a txt file too. Therefore, I have to put command and perl together.
    It just kile this:
    #!/usr/bin/perl
    $user = <STDIN>;
    system("useradd $user -d/home/myfolder/$user -g GROUP");
    open (SAVEINFO,">$user.txt");
    print SAVEINFO "infomation here!!!";
    close (SAVEINFO);
    but I think I got the problem with the line 4 (system("useradd $user -d/home/myfolder/$user -g GROUP").

  4. #4
    Linux Enthusiast
    Join Date
    Dec 2004
    Posts
    637
    is this a home work question?

  5. #5
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7
    yes, it is !
    You have any idea with it?
    Thanks
    KHOA

  6. #6
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Homework questions are forbidden under the forum rules.

    I will tell you that it has something to do with $user.

  7. #7
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7
    Hi, Cabhan!
    can you give me more tips about that?
    I cant find any solutions for that.
    Thanks
    KHOA

  8. #8
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7
    When I run this script. The user is created, however it is created on Home dir, not on student folder . And it also report that cannot find
    -d /home/sudent/username
    and : -g can find command
    Plzzz help me out :L

  9. #9
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,882
    Quote Originally Posted by khoa263
    When I run this script. The user is created, however it is created on Home dir, not on student folder . And it also report that cannot find
    -d /home/sudent/username
    and : -g can find command
    Plzzz help me out :L
    You can modify the way the useradd script works by changing the arguments you pass to it. Check out its help and/or manpages for some hints. You'll need to learn how to craft the command line arguments to make this happen the way you want.

    Good luck.
    Linux user #126863 - see http://linuxcounter.net/

  10. #10
    Just Joined!
    Join Date
    Aug 2006
    Posts
    7
    can you tell me more?, I already try it 1 week, and next morning I have to give it to my teacher. plzz

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •