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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |