-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixsql.sh
executable file
·45 lines (32 loc) · 1.48 KB
/
fixsql.sh
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
#!/bin/bash
# hacksql
# Hacks moodle database sql file, replacing the search value with the replacevalue
search="" # Serach for
replace="" # Repalce with
datbase="" # SQL file to process
while getopts "s:r:d:h" param; do
case "${param}" in
s) search="$OPTARG";;
r) replace="$OPTARG";;
d) replace="$OPTARG";;
h) printf "Usage hacksql -s <search term> -r <replace term> -d <sql file>" \n"
printf "example: hacksql -s 'sit-lms.literacyhub.edu.au' -r 'merlin.lih_moodle.edu.au' -d 'lih_moodle_database_bak_sit_38.221121.sql' \n"
exit 2;;
?) printf "Usage hacksql -s <search term> -r <replace term> -d <sql file> \n"
printf "example: hacksql -s 'sit-lms.literacyhub.edu.au' -r 'merlin.lih_moodle.edu.au' -d 'lih_moodle_database_bak_sit_38.221121.sql' \n"
exit 2;;
esac
done
shift $((OPTIND-1))
if [ ! -z "${search}" ] && [ ! -z "${replace}" ] && [ ! -z "${database}" ]; then
oldsite='sit-lms.literacyhub.edu.au'
newsite='merlin.lih_moodle.edu.au'
echo "sed -e \"s/${search}/${replace}/g\" ${database} > nu_${database}"
sed -e "s/${search}/${replace}/g\" "${database} > nu_${database}"
else
printf "Usage hacksql -s <search term> -r <replace term> -d <sql file>" \n"
exit 2
fi
# oldsite='sit-lms.literacyhub.edu.au'
# newsite='merlin.lih_moodle.edu.au'
# echo "sed -e \"s/$oldsite/$newsite/g\" lih_moodle_database_bak_sit_38.221121.sql > lih_moodle_database_merlin.sql"