summaryrefslogtreecommitdiffstats
path: root/Aufgabe7/db-passwd-fill-table.pl
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2016-01-06 17:38:26 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2016-01-06 17:38:51 +0100
commit853dfabf5172b66316849b8ef4fe92b9933677ad (patch)
treecb14fc68e6153f1cef3b1d842ec9e0174e572a49 /Aufgabe7/db-passwd-fill-table.pl
parent96de4c9dde901d059b4885bc088f0a6b2e01fcb5 (diff)
downloadSkriptsprachen-853dfabf5172b66316849b8ef4fe92b9933677ad.tar.gz
Skriptsprachen-853dfabf5172b66316849b8ef4fe92b9933677ad.zip
Create a database and read the passwd file
Diffstat (limited to 'Aufgabe7/db-passwd-fill-table.pl')
-rw-r--r--Aufgabe7/db-passwd-fill-table.pl52
1 files changed, 52 insertions, 0 deletions
diff --git a/Aufgabe7/db-passwd-fill-table.pl b/Aufgabe7/db-passwd-fill-table.pl
new file mode 100644
index 0000000..c33f89a
--- /dev/null
+++ b/Aufgabe7/db-passwd-fill-table.pl
@@ -0,0 +1,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}) or die 'DB not accessible';
+
+my $passwdInsertSth = $dbhandle->prepare("INSERT INTO stsuh_passwort (loginname, password, uid, gid, comment, homedir, commandinterpreter) VALUES (?, ?, ?, ?, ?, ?, ?)") or die 'Preparation failed';
+
+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 'Execution failed';
+}
+
+close $passwdFile
+ or warn "$0 : failed to close input file '$passwdFile_file_name' : $!\n";
+
+$dbhandle->disconnect;