first, please use code tags. As for your question of breaking
out, check the return value of system ($?). Most unix commands return 0 upon success and something else upon failure (not quite sure what the failure codes are for adduser but I get
a 9 when you try to add an all ready existing user).
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my ($username, $password, $domain);
my $result = GetOptions("username=s" => \$username,
"password=s" => \$password,
"domain=s" => \$domain );
system("/usr/sbin/adduser $username -g 100 -s /bin/false -d /home/$use
+rname -p $password");
if( $? >> 8 == 0 ) {
# success
open (VFILE, ">> virtual"); # you should check for failure here
print VFILE "$username\@ap3k.com\t$username\n";
close (VFILE);
# Do you need to check this?
system ("postmap /etc/postfix/virtual");
} else {
print STDERR "bailing with ret code of ", $? >> 8, "\n";
}
see system on interpretting return codes
(that shifty bit stuff).
-derby
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.