summaryrefslogtreecommitdiffstats
path: root/Aufgabe7/db-passwd-fill-table.pl
blob: 0b796930ee0ac36ac0cde1f348671367118c3b18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env perl 
#===============================================================================
#
#         FILE: db-passwd-fill-table.pl
#
#        USAGE: ./db-passwd-fill-table.pl  
#
#  DESCRIPTION: 
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: Stefan Suhren (su), suhren.stefan@fh-swf.de
# ORGANIZATION: FH Südwestfalen, Iserlohn
#      VERSION: 1.0
#      CREATED: 06.01.2016 14:24:22
#     REVISION: ---
#===============================================================================

use strict;
use warnings;
use utf8;

# Add database modul
use DBI;

# Get database config
my %dbconf = do 'dbinc.pl';

my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}, {RaiseError=>1}) or die 'DB not accessible';

my $passwdInsertSth = $dbhandle->prepare("INSERT INTO stsuh_passwort (loginname, password, uid, gid, comment, homedir, commandinterpreter) VALUES (?, ?, ?, ?, ?, ?, ?)") or die $dbhandle->errstr;

my	$passwdFile_file_name = 'passwd';		# input file name

open  my $passwdFile, '<', $passwdFile_file_name
	or die  "$0 : failed to open  input file '$passwdFile_file_name' : $!\n";

while (<$passwdFile>)
{
	my @passwdLine = split(':', $_);

	chomp @passwdLine;

	$passwdInsertSth->execute(@passwdLine) or die $dbhandle->errstr;
}

close  $passwdFile
	or warn "$0 : failed to close input file '$passwdFile_file_name' : $!\n";

$dbhandle->disconnect;