-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_user.sh
More file actions
executable file
·61 lines (55 loc) · 1.57 KB
/
delete_user.sh
File metadata and controls
executable file
·61 lines (55 loc) · 1.57 KB
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
#!/bin/bash -ue
usage_exit() {
echo "Usage: $0 [-a] [-t username] [-r regexp?] ..." 1>&2
exit 1
}
usage_help(){
echo "Usage: ./delete_user.sh [OPTIONS] [ARGS]"
echo " This script is for deleting user information to initialize database of JavaEP."
echo
echo "Options:"
echo " -h, help"
echo " -a, don't need any arg. delete all users without admin."
echo " -r [regexp?], ex) -r '^[0-9]+$', delete students using regular expression."
echo " -t [username], ex) -t wanaka, delete the user."
echo
exit 1
}
while getopts ":t:ar:h" OPT
do
case $OPT in
a) OPT_FLAG_a=1;;
t) OPT_FLAG_t=1;OPT_VALUE_t=$OPTARG ;;
r) OPT_FLAG_r=1;OPT_VALUE_r=$OPTARG ;;
h) usage_help;;
:) echo "[ERROR] Option argument is undefined.";;
\?) echo "[ERROR] Undefined options.";usage_exit;;
esac
done
shift $(($OPTIND - 1))
if [ -n "${OPT_FLAG_a+UNDEF}" ];then
cd ./db
sed -e "s/targetuser/admin/g" delete_user.sql > tmp.sql
sed -e "3,9s/=/!=/g" tmp.sql > delete_user_exec.sql
mysql -u javaep -p < delete_user_exec.sql
rm delete_user_exec.sql
rm tmp.sql
cd ../
fi
if [ -n "${OPT_FLAG_r+UNDEF}" ];then
echo ${OPT_VALUE_r}
cd ./db
sed -e "s/targetuser/${OPT_VALUE_r}/g" delete_user.sql > tmp.sql
sed -e "3,9s/=/regexp/g" tmp.sql > delete_user_exec.sql
mysql -u javaep -p < delete_user_exec.sql
rm delete_user_exec.sql
rm tmp.sql
cd ../
fi
if [ -n "${OPT_FLAG_t+UNDEF}" ];then
cd ./db
sed -e "s/targetuser/${OPT_VALUE_t}/g" delete_user.sql > delete_user_exec.sql
mysql -u javaep -p < delete_user_exec.sql
rm delete_user_exec.sql
cd ../
fi