-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesLaborable.sh
More file actions
executable file
·51 lines (43 loc) · 1.58 KB
/
esLaborable.sh
File metadata and controls
executable file
·51 lines (43 loc) · 1.58 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
#!/bin/bash
[ ! -f .env ] || export $(grep -v '^#' .env | xargs)
source /opt/tp/scripts/generalPrint.sh
unset query[3]
function tercer_lunes {
MES=$1
# Calculo el tercer lunes del mes
for D in 01 02 03 04 05 06; do
[ "`date --date \"$ANIO-$MES-$D\" +'%w'`" -eq 1 ] && DIA="$ANIO-$MES-$D"
done
FTL=`date --date "$DIA 14 days" +'%d/%m/%Y'`
}
function esLaborable {
dateX=$1
[[ -z $dateX ]] && dateX=$(date +"%Y/%m/%d")
if [[ $dateX =~ ^([0-9]{4}).*([0-9]{2}).*([0-9]{2})$ ]]; then
validateX=$(sed -r 's/^([0-9]{4}).*{1}([0-9]{2}).*{1}([0-9]{2})$/\1\/\2\/\3/' <<< $dateX)
#stable
mysql -u root -p${PASS_MYSQL_ROOT} feriados << EOF && mv /var/lib/mysql-files/results.csv $PWD/
SELECT
feriados.fecha,
tipo_feriado.tipo,
feriados.titulo FROM
tipo_feriado INNER JOIN
feriados
ON tipo_feriado.id_tferiado = feriados.id_tferiado
WHERE feriados.fecha = "$validateX"
INTO OUTFILE '/var/lib/mysql-files/results.csv'
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n';
EOF
else
PrinterLog 3 "validacion de fecha" "la fecha $dateX al parecer no es una fecha"
echo "" > results.csv
fi
query[0]=$(sed -r 's/\"(.*)\"/\1/' <<< $(cut -d ';' -f1 results.csv))
query[1]=$(sed -r 's/\"(.*)\"/\1/' <<< $(cut -d ';' -f2 results.csv))
query[2]=$(sed -r 's/\"(.*)\"/\1/' <<< $(cut -d ';' -f3 results.csv))
#[[ -z ${query[0]} && -z ${query[1]} && -z ${query[2]} ]] || echo "${query[1]}" "${query[2]}"
#comprobar esta validacion
[[ -z ${query[0]} && -z ${query[1]} && -z ${query[2]} ]] && PrinterLog 4 "Base de datos" "no hay feriado" || PrinterLog 4 "Base de datos" "${query[2]}"
}