No they don't. Nor does passwd need a tty. You can run a script like this without any tty or user input.

#!/usr/bin/perl -w use strict; $|++; my $HOME_DIR = '/home/'; my $MAIL_DIR = '/var/mail/'; my $CRAM_FILE = '/etc/cram-md5.pwd'; my $USERADD_BIN = '/usr/sbin/useradd'; my $PASSWD_BIN = '/usr/bin/passwd'; my $PASSWD_FILE = '/etc/passwd'; my $HTPASSWD_BIN = '/usr/bin/htpasswd'; my $HTPASSWD_FILE = '/home/www/.htpasswd'; print "Username: "; chomp(my $user = <>); if(`grep /$user:/ $PASSWD_FILE`) { print "Username '$user' already exists! Continue (default=y) [y/n] +: "; exit if <> =~ /n/i; } else { `$USERADD_BIN "$user"`; } print "Shell Password: "; chomp(my $shellpwd = <>); if ($shellpwd) { open PWD, "|$PASSWD_BIN --stdin $user" or die "Can't open pipe to +$PASSWD_BIN $!\n"; print PWD $shellpwd, "\n"; close PWD; } else { print "No shell account password will be added!\n"; } $shellpwd ||= 'password'; print "POP3 password (default='$shellpwd'): "; chomp(my $pop3pwd = <>); print "Shell and POP3 passwords will be the same!\n" unless $pop3pwd; $pop3pwd ||= $shellpwd; # avoid duplicate entries in cram-md5.pwd open PWD, "<$CRAM_FILE" or die "Can't read $CRAM_FILE $!\n"; my @old_cram = grep { ! /$user\t/ } <PWD>; close PWD; print "Adding POP3 password to /etc/cram-md5.pwd\n"; open PWD, ">$CRAM_FILE" or die "Can't write $CRAM_FILE $!\n"; print PWD @old_cram, "$user\t$pop3pwd\n"; close PWD; print "Add to .htaccess (default=y) [y/n]: "; unless ( <> =~ m/n/i ) { `$HTPASSWD_BIN -b $HTPASSWD_FILE $user "$pop3pwd"`; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: useradd with perl and cron by tachyon
in thread useradd with perl and cron by true

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.