-
Notifications
You must be signed in to change notification settings - Fork 1
/
db_suite.sh
79 lines (66 loc) · 2.75 KB
/
db_suite.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
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
#!/bin/bash
# DB Suite роутер
# Автор: Олег Букатчук
# Версия: 1.9
# e-mail: oleg@bukatchuk.com
# Подключаем конфиг
source "./config.sh"
# Тип БД (1-й параметр к скрипту)
export DB_TYPE=$1
# Действие с БД (2-й параметр к скрипту)
export ACTION_TYPE=$2
# Зеленый цвет
export SETCOLOR_SUCCESS="echo -en \\033[1;32m"
# Красный цвет
export SETCOLOR_FAILURE="echo -en \\033[1;31m"
# Цвет по умолчанию
export SETCOLOR_NORMAL="echo -en \\033[0;39m"
#####################################################################################################################
# Проверка аргументов перед запуском скриптов
# $# переменная, содержащая количество аргументов, преданных скрипту.
# -eq 2 проверяем, равняется ли количество переданных аргументов двум.
# $0 возвращает путь к shell скрипту.
if [ $# -eq 2 ];
then
echo "Укажите параметры запуска: $0 условие1 условие2";
exit 1;
else
# Команда, которую нужно отследить
# printf 'Введите параметры запуска:'
# Читаем ввод из консоли
# read INPUT
# Ловим параметры и запускаем соответствующий параметрам скрипт
case `$0 ${DB_TYPE} ${ACTION_TYPE}` in
"$0 mysql backup")
sudo ${DB_SUITE}/mysql/mysql_backup.sh
;;
"$0 mysql tunning")
sudo ${DB_SUITE}/mysql/mysql_tunning.sh
;;
"$0 postgresql backup")
sudo ${DB_SUITE}/postgresql/postgresql_backup.sh
;;
"$0 postgresql tunning")
sudo ${DB_SUITE}/postgresql/postgresql_tunning.sh
;;
*)
echo "Не верно заданы параметры запуска."
;;
esac
fi
#####################################################################################################################
# Вывод результата выполнения скриптов
if [ $? -eq 0 ];
then
${SETCOLOR_SUCCESS}
echo -n "$(tput hpa $(tput cols))$(tput cub 6)[OK]"
echo -n "Путь к скрипту: $0"
${SETCOLOR_NORMAL}
echo
else
${SETCOLOR_FAILURE}
echo -n "$(tput hpa $(tput cols))$(tput cub 6)[fail]"
echo -n "Путь к скрипту: $0"
${SETCOLOR_NORMAL}
echo
fi