· 8 years ago · Jul 12, 2018, 01:36 PM
1#!/bin/bash
2# Skript: M122_Scripts/SQLUser.sh
3
4datenbank="$PWD/linuxusers.db"
5
6sqlite3 linuxusers.db << EOF
7drop table if exists LinuxBenutzer;
8create table if not exists LinuxBenutzer (id integer primary key autoincrement, UserName text, UID integer, GID integer, Home);
9EOF
10
11IFS=$'\n'
12
13for user in $(cat users.txt)#$(egrep "10[0-9]{2}|^root" /etc/passwd)
14do
15 # with EGREP change the -f arguments to -f1,3-4,6
16 f1=$(echo $user | cut -d$'\t' -f1)
17 f2=$(echo $user | cut -d$'\t' -f2)
18 f3=$(echo $user | cut -d$'\t' -f3)
19 f4=$(echo $user | cut -d$'\t' -f4)
20
21# commented out for presentation purposes
22# echo $f1
23# echo $f2
24# echo $f3
25# echo $f4
26
27sqlite3 linuxusers.db << EOF
28insert into Linuxbenutzer (UserName, UID, GID, Home) values ('$f1', '$f2', '$f3', '$f4');
29EOF
30done
31
32sqlite3 linuxusers.db << EOF
33.header on
34.mode column
35select * from LinuxBenutzer;
36EOF