-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.sh
150 lines (144 loc) · 3.63 KB
/
base.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
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
150
#!/usr/local/bin/bash
##
# base.bash
###
n_day=`date +%e | tr -d '[:space:]'`
h_start=`date '+%H:%M'`
to_day=`date '+%Y%m%d'`
yesterday=`date -v-1d '+%Y%m%d'`
date_string=`date +%d/%m/%Y`
log_dir=/var/log
hostname=`uname -n`
os=`uname -sr`
access=sudo
scriptpath='/ziz/scripts'
print_head ()
{
clear
strlen=$(echo $1 | wc -c)
spaces=$(expr 54 - $strlen)
spaces=$(expr ${spaces} / 2)
print_margin $spaces
echo "${1}"
echo " "
echo " ${date_string} ${hostname}"
echo
}
print_margin ()
{
x=1
while [ true ]; do
echo -n " "
if [ $x -gt $1 ]; then
break
fi
let x=$x+1
done
unset x
}
get_selected ()
{
unset func
unset arg1
unset arg2
echo -e " Seleccione opción :\c "
sw=0
while [ $sw -eq 0 ]; do
read op
if [[ 'q' == $op || 'Q' == $op ]]; then
exit 0
fi
x=1
for opt in $(cat ${scriptpath}/${1}.opt) ; do
if [ $x -eq $op ]; then
func=$(echo ${opt} | awk '{split($0, a, ";");print a[2]}')
func=$(echo $func | tr -d ' ')
export func
arg1=$(echo ${opt} | awk '{split($0, a, ";");print a[3]}')
arg1=$(echo $arg1 | tr -d ' ')
export arg1
arg2=$(echo ${opt} | awk '{split($0, a, ";");print a[4]}')
export arg2
sw=1
fi
let x=$x+1
done
if [ $sw -eq 0 ] ; then
clear
print_menu $1 $2
continue
fi
if [ $sw -eq 1 ]; then
$func $arg1 $arg2
fi
done
}
get_sub_selected ()
{
unset func
unset arg1
unset arg2
echo -e " Seleccione opción :\c "
sw=0
while [ $sw -eq 0 ]; do
read op
x=1
if [[ 'q' == $op || 'Q' == $op ]]; then
sw=1
return 0
fi
for opt in $(cat ${scriptpath}/${1}.opt) ; do
if [ $x -eq $op ]; then
func=$(echo ${opt} | awk '{split($0, a, ";");print a[2]}')
func=$(echo $func | tr -d ' ')
export func
arg1=$(echo ${opt} | awk '{split($0, a, ";");print a[3]}')
export arg1
arg2=$(echo ${opt} | awk '{split($0, a, ";");print a[4]}')
export arg2
sw=2
fi
let x=$x+1
done
if [ $sw -eq 0 ] ; then
clear
print_sub_menu $1 $2
continue
fi
if [ $sw -eq 2 ]; then
$func $arg1 $arg2
fi
done
}
print_menu ()
{
IFS=$'\n'
i=0
print_head $2
for str in $(cat ${scriptpath}/${1}.opt); do
let i=$i+1
echo -n " ${i}) "
echo $str | awk '{split($0, a, ";");print a[1]}'
done
# let i=$i+1
# echo " ${i}) Salir"
echo " Q) Salir"
echo;echo
get_selected $1 $2
}
print_sub_menu ()
{
IFS=$'\n'
i=0
print_head $2
for str in $(cat ${scriptpath}/${1}.opt); do
let i=$i+1
echo -n " ${i}) "
echo $str | awk '{split($0, a, ";");print a[1]}'
done
# let i=$i+1
# echo " ${i}) Volver"
echo " Q) Volver"
echo;echo
get_sub_selected $1 $2
}