Re: adduser without ncurses?

From: Theorem (Theorem_at_Axiometric.NOSPAMPLEASE.org)
Date: 06/20/04

  • Next message: phn_at_icke-reklam.ipsec.nu: "Re: adduser without ncurses?"
    Date: Sun, 20 Jun 2004 07:30:59 -0400
    
    

    Erica wrote:

    > (I may have accidently posted this twice, if so, I apologize)
    >
    > Hi,
    >
    > I wrote a script to add a whole bunch of users to a FreeBSD box using input from
    > a file. However, I need something that works like adduser or useradd
    > without ncurses, that is, without prompting for input. Something that
    > allows me to just place all the arguments on a single line so that I can
    > run it in an awk loop. If anyone knows of such a thing, I would be ever
    > grateful for your assistance.

    I do this with a perl script that reads the file and then calls pw to
    create the account (without a password). The perl script then writes a
    temporary expect script that when run will set the password, then the
    perl script runs the expect script, and finally the perl script
    unlinks the expect script.

    Here's some perl code that does the account creation and password
    changing. I leave the file reading and variable setting to you. You
    may want other switches in your pw command as well.

    #!/usr/bin/perl
    # loop to read file and set variables and then...
    system("/usr/sbin/pw useradd -n $user -c $name -m -s $shell")
            == 0 or die "Error creating $user account: $?";
    open PWC, ">pwc"
            or die "Could not write $user expect script: $?";
    print PWC <<EOL;
    #!/usr/local/bin/expect
    set argv $user
    spawn -noecho passwd [lindex \$argv 0]
    expect "Changing local password for $user."
    send ""
    expect "password:"
    send "$pass\r"
    expect "password:"
    send "$pass\r"
    expect eof
    EOL
    close PWC;
    chmod 0750, pwc;
    system("./pwc >> /dev/null")
            == 0 or die "Error setting $user pwd: $?";
    unlink pwc;


  • Next message: phn_at_icke-reklam.ipsec.nu: "Re: adduser without ncurses?"

    Relevant Pages

    • Re: adduser without ncurses?
      ... I do this with a perl script that reads the file and then calls pw to ... I leave the file reading and variable setting to you. ... open PWC, ">pwc" ...
      (comp.unix.bsd.freebsd.misc)
    • [NEWS] IBM Informix Web DataBlade Local Root by Design
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... that ease development of "intelligent", interactive, Web-enabled database ... person who has access to change the Perl script. ...
      (Securiteam)
    • my perl script for ripping mp3s...aka MP3scRIPt
      ... This is a Perl script to convert audio cd tracks to mp3s. ... Possibly root privs to access the cdrom device ... - this is mainly a problem on 'variety cds', mp3 files suffering from this ill ...
      (comp.unix.bsd.freebsd.misc)
    • Re: Perl script to mimic uniq
      ... mdfoster44@netscape.net spits TOFU in my face: ... > # Perl script to find most common CS ... > So I'm back to my original script which looks like this. ... > identify a sequence as unique. ...
      (comp.lang.perl)
    • Re: Slow Performance When Using DBI, otherwise Not
      ... If I run the same perl script on the database server itself it runs ... check versions of DBI and DBD (I greped for version on every module under ...
      (perl.dbi.users)