-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch-csv-mysql
executable file
·149 lines (110 loc) · 3.74 KB
/
watch-csv-mysql
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
# Bash utility that calls a directory-watching Bash utility with a custom shell script
#
# Example:
# ./watch-csv-mysql -d sandbox/test -c csv-mysql -h localhost -u root -p password -D DOkwufulueze -t profile
helpText=;
directory=;
commandName=;
commandEntry=;
userNameComposition=;
passwordComposition=;
hostComposition=;
portComposition=;
databaseComposition=;
tableComposition=;
fileNameComposition=;
function displayHowToUse() {
helpText=$(cat << EOF
watch-csv-mysql
Version: 1.0.0
Usage:
watch-csv-mysql [OPTIONS]
Options:
<-d | --directory directoryName>
<-c | --command commandName>
<-f | --filename filename>
<-h | --host host>
<-P | --port port>
<-u | --username username>
<-p | --password password>
<-D | --database database>
<-t | --table table>
</? | --help>
Synopsis:
Purpose: This script watches any directory for changes
such as an addition of a CSV file and calls the watch-directory
script with a command to transfer the contents of the CSV file
to a chosen MySQL database.
Options:
-d | --directory: This option receives the name of the directory to watch.
-c | --command: This option receives the name of the command to run wheneve a change happens to the directory.
-f | --filename: This option receives the name of the CSV file whose content you want to transfer to the Database.
-h | --host: This option receives the host upon which the Database server is running.
-P | --port: This option takes the port number upon which the Database server is running.
-u | --username: This option accepts the username of the database server.
-p | --password: This option receives the user\'s password to the database server.
-D | --database: This option accepts the name of the database server.
-t | --table: This option takes the name of the database table into which the CSV content will be transferred.
/? | --help: This option displays this help page.
Author: Daniel Okwufulueze [https://github.com/DOkwufulueze]
Date: 02/05/2018
EOF
);
}
if [[ $# -gt 0 ]]; then
while [[ "$1" != "" ]]; do
case "$1" in
-d | --directory )
shift;
directory="$1";
;;
-c | --command )
shift;
commandName="$1";
;;
-f | --filename )
shift;
fileNameComposition="-f $1";
;;
-u | --username )
shift;
userNameComposition="-u $1";
;;
-p | --password )
shift;
passwordComposition="-p $1";
;;
-h | --host )
shift;
hostComposition="-h $1";
;;
-P | --port )
shift;
portComposition="-P $1";
;;
-D | --database )
shift;
databaseComposition="-D $1";
;;
-t | --table )
shift;
tableComposition="-t $1";
;;
/? | --help )
displayHowToUse;
echo "${helpText}" | less;
exit;
;;
* )
echo "Invalid entry in watch-csv-mysql invocation.";
exit;
;;
esac
shift;
done
fi
commandEntry="./${commandName} ${hostComposition} ${portComposition} ${userNameComposition} ${passwordComposition} ${databaseComposition} ${tableComposition}";
# echo "./watch-directory -d ${directory} -c ${commandEntry}";
echo " watching ${directory} for changes...";
$(./watch-directory -d "${directory}" -c "${commandEntry}");