-
Notifications
You must be signed in to change notification settings - Fork 1
/
MenuJobs.sh
executable file
·183 lines (131 loc) · 3.45 KB
/
MenuJobs.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#Global Variables
GNAME="NULL";
GTMP="/tmp";
function IPeUser()
{
#funcao que recebe uma variavel para preencher nome do minionn
local minionpadrao="minion1"
local listminions=/tmp/listminions.txt
dialog --cr-wrap --sleep 1 --infobox "Procurando Minions Disponíveis..." 0 0
echo -e "$(sudo salt '*' test.ping -s --out=txt | sed "s/\://g" )" > $listminions
local minions=$(cat $listminions)
minionpadrao=$(dialog --stdout --menu 'Escolha o Minion:' 0 0 0 \
`
for x in $minions; do
echo " $x ";
done;
`);
#Valida se houve uma selecao de usuario ou nao
if [ $? -eq 1 ]; then
dialog --cr-wrap --sleep 2 --title 'Tente Novamente' --infobox "Nenhum escolhido" 5 17
Menu;
# else
# dialog --cr-wrap --sleep 1 --infobox "Escolhido $minionpadrao" 0 0
fi
#retorna valores
eval "$1=$minionpadrao"
}
function ListAllJobs()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
#local mycommand="tree /srv/salt -L 1 | grep -v sls | grep -v directories"
#SelectTree $mycommand mychoice
#dialog --cr-wrap --sleep 2 --infobox "Escolhi: $mychoice" 0 0
#SelectViewDoTest $mychoice commandtorun
#dialog --cr-wrap --sleep 2 --infobox "Recebi: $commandtorun" 0 0
#
#echo -e "$(sudo salt $myminion state.show_highstate --out=json | grep __sls__ | sed 's/, *$//' | sort -u | awk '{print $2}')" > $todialog
#comando mais simples
echo -e "$(sudo salt-run jobs.list_jobs search_target=$myminion )" > $todialog
dialog --title "All Jobs: " --textbox $todialog 45 50
Menu
}
function ListRunsJobs()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
echo -e "$(sudo salt-run jobs.last_run target=$myminion )" > $todialog
dialog --title 'Jobs last_run for $myminion' --textbox $todialog 0 0
Menu
}
function RunTopState()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
echo -e "$(sudo salt $myminion state.show_top | grep " - " | tr -s [:space:] | sed "s/ \- //g")" > $todialog
#local mycommand=$(cat $todialog)
SelectFunction mychoice
#dialog --cr-wrap --sleep 2 --infobox "Escolhi: $mychoice" 0 0
SelectViewDoTest $myminion $mychoice
dialog --title 'Documentation' --textbox $todialog 0 0
Menu
}
function RunHighState()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser mymini
myselect=$(dialog --stdout --radiolist 'Opcoes' 0 0 0 \
run 'Run / Executar ' off \
testonly 'Test / Testar ' on \
viewonly 'View / Vizualizar ' off);
case $myselect in
"run")
#echo "tree-only"
echo -e "$(sudo salt $mymini state.highstate)" > $todialog
;;
"testonly")
#echo "all-files"
echo -e "$(sudo salt $mymini state.highstate test=true)" > $todialog
;;
"viewonly")
#echo "all"
echo -e "$(sudo salt $mymini state.show_highstate )" > $todialog
;;
*)
echo "Menu Inválido!"
;;
esac
dialog --title 'Documentation' --textbox $todialog 0 0
Menu
}
function Menu()
{
clear
menuopt=$(dialog --menu "Menu" 20 35 15 \
1 "List All Jobs" \
2 "List Running Jobs" \
3 "List Active Jobs" \
4 "Lookup Job" \
5 "Kill a Job" \
9 "Exit" --stdout)
case $menuopt in
1)
ListAllJobs
;;
2)
ListRunsJobs
;;
3)
ListActJobs
;;
4)
LookupAJob
;;
5)
KillJob
;;
9) ./Main.sh
;;
*) echo "Menu Inválido!" ;;
esac
}
function Iniciar(){
Menu
}
Iniciar