Hey guys, I have the following problem. I have created the following code where I add to the database all the usernames and passwords automatically that are in the text file.
#!/usr/bin/perl -w use DBI; # connect to the database my $dbh = DBI->connect('dbi:mysql:ass2db', 'test', '123') or die "Can't connect: ", $DBI::errstr; # prepare a SQL statement to insert your data # (using placeholders ("?") so you only have to # compile the statement once) my $sth = $dbh->prepare(<<SQL) or die "Can't prepare: ", $dbh->errstr; insert into ASS2 (User_name, Pass) values (?, ?) SQL # open up your data file open FILE, "data.txt" or die "Can't open: $!"; while (<FILE>) { chomp; # parse your data out of the file my($d1, $d2) = split(':', $_); # assuming tab-separated data #use system command to add user and set passwd system "useradd -m -p $d1 $d2"; # insert your data into the database $sth->execute($d1, $d2); } close FILE; $sth->finish; $dbh->disconnect;
This code works like a charm, now the problem is that I need to do the same process but removing the usernames and passwords using the text file.
the data.txt contains: user1:password1 user2:password2
I have tried everything and I cannot make it work. Im a total newbie with perl and I suck at programming so it makes it really hard for me. Any ideas would be much appreciated. Thanks
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |