hello all monks finally i did it and i wrote that script tahnks for all who help me
#!/usr/bin/perl -w
use strict;
use DBI;
use diagnostics;
#step1 - create connection objection .
my $dsn = 'DBI:mysql:backupDB';
my $user = 'adam';
my $password = 'secret';
my $conn = DBI->connect($dsn,$user,$password) || die "Error connecting
+" . DBI->errstr;
my $file = "/etc/passwd";
open (han1, "$file") || die "error opening file: $!";
my @newrecords = <han1>;
foreach (@newrecords) {
my @columns = split /:/;
my $username = $columns[0];
my $x = $columns[1];
my $userid = $columns[2];
my $groupid = $columns[3];
my $realname = $columns[4];
my $homedir = $columns[5];
my $shellpath = $columns[6];
$conn->do("insert into users(username,x,userid,groupid,realname,homedi
+r,shellpath) values('$username','$x','$userid','$groupid','$realname'
+,'$homedir','$shellpath')") || die "error preparing query" . $conn->e
+rrstr;
}
the last thing i want to know is
how can i make this operation updated i mean if i add new user for example how can i make the program to fetch the new records and add to the database
|