Compare commits
29 Commits
05475361e8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb67db2a78 | ||
|
|
71cf1ec44c | ||
|
|
ed19ae5c0d | ||
|
|
c4d9e053ee | ||
|
|
8d88743624 | ||
|
|
2cdab60efb | ||
|
|
c761fe5d93 | ||
|
|
4342f0a5f8 | ||
|
|
be7e5da172 | ||
|
|
4174b3f7e3 | ||
|
|
9d5f5eac9f | ||
|
|
4f2f11bd1a | ||
|
|
d61329011b | ||
|
|
4292b8e4dc | ||
|
|
5c930248eb | ||
|
|
9bc3710c32 | ||
|
|
287a1fd2d3 | ||
|
|
aac91e9a55 | ||
|
|
fd8ad9799b | ||
|
|
3c42aff8f5 | ||
|
|
26460cf7f5 | ||
|
|
8a3654e42b | ||
|
|
855352bdf4 | ||
|
|
f5af07290e | ||
|
|
f0d521b49a | ||
|
|
4d0bf673a5 | ||
|
|
bf5c616f01 | ||
|
|
0f7cddd5a6 | ||
|
|
1e5e310fc8 |
@@ -2,10 +2,6 @@
|
||||
|
||||
. /etc/profile
|
||||
|
||||
# export all functions
|
||||
set -a
|
||||
|
||||
|
||||
## Include functions
|
||||
for bashfunc in $(find /etc/bash/gaboshlib -type f -name "g_*.bashfunc" -o -name "g_*.sh")
|
||||
do
|
||||
@@ -34,7 +30,7 @@ g_tmp="$g_tmp/g_$g_scriptname-$$"
|
||||
|
||||
# START and EXIT Notification
|
||||
g_trap_exit="g_logger EXITING $g_scriptname ; rm -r $g_tmp ; g_kill_all_background_jobs >/dev/null 2>&1"
|
||||
trap "$g_trap_exit" EXIT
|
||||
trap "$g_trap_exit" INT TERM EXIT
|
||||
g_syslogtag="g_bash-script:$g_scriptname[$$]"
|
||||
[ $g_scriptname = "bash" ] || g_logger STARTING $g_scriptname
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ vpn
|
||||
.config/Nextcloud/
|
||||
nextcloud-test.*/
|
||||
.VirtualBox/
|
||||
VirtualBox/
|
||||
DMS/
|
||||
tmp
|
||||
.zoom/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function g_basename {
|
||||
g_basename_result="${1##*/}"
|
||||
g_basename_result="${g_basename_result:-/}"
|
||||
g_basename_result=${1##*/}
|
||||
g_basename_result=${g_basename_result:-/}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,11 @@ function g_calc {
|
||||
|
||||
unset g_calc_result
|
||||
|
||||
local g_jobs
|
||||
mapfile -t g_jobs < <(jobs -r)
|
||||
|
||||
# check if bc is already running
|
||||
if [[ -z "$g_fd_bc_in" || -z "$g_fd_bc_out" ]]
|
||||
if [[ -z "$g_fd_bc_in" || -z "$g_fd_bc_out" || ${g_jobs[*]} != *bc* ]]
|
||||
then
|
||||
local bc_input="$g_tmp/$$-g_bc_input"
|
||||
local bc_output="$g_tmp/$$-g_bc_output"
|
||||
@@ -22,9 +25,30 @@ function g_calc {
|
||||
# send calculation and read result
|
||||
echo "$1" >&${g_fd_bc_in}
|
||||
read -u ${g_fd_bc_out} g_calc_result
|
||||
g_calc_result=${g_calc_result//-./-0.}
|
||||
g_calc_result=${g_calc_result//./0.}
|
||||
if ! g_num_valid_number $g_calc_result
|
||||
|
||||
# check if there is a output
|
||||
if [ -z "$g_calc_result" ]
|
||||
then
|
||||
echo "${FUNCNAME} $@" 1>&2
|
||||
unset g_calc_result
|
||||
return 1
|
||||
fi
|
||||
|
||||
# fix bc output -> change for example .224 to 0.224 and -.224 to -0.224
|
||||
[[ $g_calc_result == "."* ]] && g_calc_result="0$g_calc_result"
|
||||
[[ $g_calc_result == "-."* ]] && g_calc_result="-0.${g_calc_result#-.}"
|
||||
|
||||
# remove ending 0 if for exabple 4.54300000
|
||||
while [[ $g_calc_result =~ [.] && ${g_calc_result: -1} == "0" ]]
|
||||
do
|
||||
g_calc_result=${g_calc_result: : -1}
|
||||
done
|
||||
|
||||
# remove ending . for example "100." -> 100
|
||||
[[ $g_calc_result == *"." ]] && g_calc_result=${g_calc_result%?}
|
||||
|
||||
# check output
|
||||
if ! g_num_valid_number "$g_calc_result"
|
||||
then
|
||||
echo "${FUNCNAME} $@" 1>&2
|
||||
unset g_calc_result
|
||||
|
||||
@@ -8,13 +8,12 @@ function g_kill_all_background_jobs {
|
||||
then
|
||||
kill -9 ${g_pids[*]} >/dev/null 2>&1
|
||||
else
|
||||
local g_cmdline=$1
|
||||
local g_cmdline="$1"
|
||||
local g_proc
|
||||
local g_pid
|
||||
for g_pid in "${g_pids[@]}"
|
||||
do
|
||||
echo $g_pid
|
||||
readarray g_proc < "/proc/$g_pid/cmdline"
|
||||
read g_proc < <(tr "\0" " " < /proc/${g_pid}/cmdline)
|
||||
[ "$g_proc" = "$g_cmdline" ] && kill -9 $g_pid >/dev/null 2>&1
|
||||
done
|
||||
fi
|
||||
|
||||
26
gaboshlib/g_median.sh
Normal file
26
gaboshlib/g_median.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
function g_median {
|
||||
unset g_median_result
|
||||
|
||||
# Array with numbers
|
||||
local g_numbers=("$@")
|
||||
|
||||
# sort array
|
||||
local g_sorted_numbers=($(printf "%s\n" "${g_numbers[@]}" | sort -n))
|
||||
|
||||
# number of elements
|
||||
local g_num_elements=${#g_sorted_numbers[@]}
|
||||
|
||||
# calculate the middle
|
||||
local g_middle=$(($g_num_elements/2))
|
||||
|
||||
# even/odd number
|
||||
if (($g_num_elements % 2 == 1))
|
||||
then
|
||||
# odd number
|
||||
g_median_result="${g_sorted_numbers[$g_middle]}"
|
||||
else
|
||||
# even number
|
||||
g_calc "(${g_sorted_numbers[$g_middle - 1]} + ${g_sorted_numbers[$g_middle]}) / 2"
|
||||
g_median_result="$g_calc_result"
|
||||
fi
|
||||
}
|
||||
@@ -5,16 +5,16 @@ function g_num_exponential2normal {
|
||||
if [[ "$1" =~ e-[0-9] ]]
|
||||
then
|
||||
# convert
|
||||
printf -v f_g_num_exponential2normal_result -- "%.12f" "$1"
|
||||
printf -v g_num_exponential2normal_result -- "%.12f" "$1"
|
||||
# remove ending 0
|
||||
if [[ $f_g_num_exponential2normal_result =~ \. ]]
|
||||
if [[ $g_num_exponential2normal_result =~ \. ]]
|
||||
then
|
||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%+(0)}
|
||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%.}
|
||||
g_num_exponential2normal_result=${g_num_exponential2normal_result%%+(0)}
|
||||
g_num_exponential2normal_result=${g_num_exponential2normal_result%%.}
|
||||
fi
|
||||
return 0
|
||||
else
|
||||
f_g_num_exponential2normal_result=$1
|
||||
g_num_exponential2normal_result=$1
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
||||
11
gaboshlib/g_num_exponential2normal_file.sh
Normal file
11
gaboshlib/g_num_exponential2normal_file.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
function g_num_exponential2normal_file {
|
||||
# changes expionential numbers in normal notation in given file
|
||||
local g_file=$1
|
||||
local g_substitution g_exnum
|
||||
for g_exnum in $(egrep -o -i "[0-9]+\.[0-9]+e[\+\-][0-9]+" "$g_file" | sort -u)
|
||||
do
|
||||
g_num_exponential2normal $g_exnum && g_substitution="${g_substitution}s/${g_exnum}/${g_num_exponential2normal_result}/g;"
|
||||
done
|
||||
sed -i "${g_substitution}" "$g_file" && return 0
|
||||
}
|
||||
|
||||
@@ -1,5 +1,62 @@
|
||||
function g_python {
|
||||
|
||||
# function for running python in the background
|
||||
# $g_fd_python_in $g_fd_python_out have to be global
|
||||
|
||||
unset g_python_result
|
||||
|
||||
local g_jobs
|
||||
mapfile -t g_jobs < <(jobs -r)
|
||||
# check if python is already running
|
||||
if [[ -z $g_fd_python_in || -z $g_fd_python_out || ${g_jobs[*]} != *python3* ]]
|
||||
then
|
||||
local python_input="$g_tmp/$$-g_python_input"
|
||||
local python_output="$g_tmp/$$-g_python_output"
|
||||
local python_error="$g_tmp/$$-g_python_error"
|
||||
# create fifo pipe
|
||||
[ -p "$python_input" ] || mkfifo "$python_input"
|
||||
[ -p "$python_output" ] || mkfifo "$python_output"
|
||||
[ -p "$python_error" ] || mkfifo "$python_error"
|
||||
# run bc in background und switch i/o to pipes
|
||||
python3 -iuq < "$python_input" > "$python_output" 2> "$python_error" &
|
||||
# store in filedescriptiors
|
||||
exec {g_fd_python_in}> "$python_input"
|
||||
exec {g_fd_python_out}< "$python_output"
|
||||
exec {g_fd_python_error}< "$python_error"
|
||||
fi
|
||||
|
||||
# read potential old output
|
||||
read -t 0.001 -u ${g_fd_python_out} g_python_result_old
|
||||
|
||||
# send python command
|
||||
echo "$@
|
||||
print('')" >&${g_fd_python_in}
|
||||
|
||||
# read output
|
||||
read -u ${g_fd_python_out} g_python_result
|
||||
|
||||
local g_errline
|
||||
local g_err_msg
|
||||
|
||||
# look for error
|
||||
while read -t 0.001 -u ${g_fd_python_error} g_errline
|
||||
do
|
||||
[[ "$g_errline" =~ \>\>\>$ ]] && break
|
||||
[ -z "$g_errline" ] && break
|
||||
g_err_msg="$g_err_msg
|
||||
$g_errline"
|
||||
done
|
||||
if [ -n "$g_err_msg" ]
|
||||
then
|
||||
g_echo_error "$g_err_msg"
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
function g_python_old {
|
||||
|
||||
local g_python_tmp=${g_tmp}/$$
|
||||
g_python_out=${g_python_tmp}/python-out
|
||||
local g_python_in=${g_python_tmp}/python-in
|
||||
|
||||
@@ -8,7 +8,7 @@ function g_read_csv {
|
||||
local g_headline=$3
|
||||
local g_separator=$4
|
||||
|
||||
local g_headline_item i l r
|
||||
local g_headline_item i l r g_csv_headline_array
|
||||
|
||||
# check for individual separator
|
||||
[ -z "$g_separator" ] && g_separator=","
|
||||
@@ -39,14 +39,20 @@ function g_read_csv {
|
||||
[ -z "$g_headline" ] && g_headline=$(head -n1 "${g_csvfile}")
|
||||
|
||||
# read the headline
|
||||
unset g_csv_headline_array_ref
|
||||
g_array "$g_headline" g_csv_headline_array_ref $g_separator
|
||||
|
||||
# prepare varnames from headline(s)
|
||||
for g_headline_item in "${g_csv_headline_array_ref[@]}"
|
||||
do
|
||||
g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9]/}")
|
||||
g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9_]/}")
|
||||
done
|
||||
|
||||
g_basename $g_csvfile
|
||||
local g_csvfile_base=${g_basename_result/\.history*.csv/}
|
||||
g_csvfile_base=${g_csvfile_base//[^a-zA-Z0-9_]/}
|
||||
g_csvfile_base=${g_csvfile_base//ECONOMY*/}
|
||||
|
||||
# read last lines if defined or complete csv file
|
||||
if [ -n "$g_last_lines" ]
|
||||
then
|
||||
@@ -54,14 +60,15 @@ function g_read_csv {
|
||||
g_csvfile="${g_tmp}/g_csv_tmp.csv"
|
||||
fi
|
||||
|
||||
|
||||
# read csv file to array
|
||||
g_array "$g_csvfile" g_csv_array_ref
|
||||
g_csv_array=("${g_csv_array_ref[@]}")
|
||||
|
||||
# go reverse through array
|
||||
# create associative arrays forward and reverse and superarray v/vr
|
||||
declare -Ag v_csv_array_associative
|
||||
declare -Ag v_csv_array_associative_reverse
|
||||
declare -Ag v
|
||||
declare -Ag vr
|
||||
l=0
|
||||
for (( r=${#g_csv_array[@]}-1 ; r>=0 ; r-- ))
|
||||
do
|
||||
@@ -75,6 +82,14 @@ function g_read_csv {
|
||||
[ "$l" = 0 ] && declare -g v_${g_headline_item}="${g_csv_line_array[i]}"
|
||||
v_csv_array_associative[${g_headline_item}_${r}]="${g_csv_line_array[i]}"
|
||||
v_csv_array_associative_reverse[${g_headline_item}_${l}]="${g_csv_line_array[i]}"
|
||||
if [ -z "${g_csvfile_base}" ]
|
||||
then
|
||||
v[${g_headline_item}_${r}]=${g_csv_line_array[i]}
|
||||
vr[${g_headline_item}_${l}]=${g_csv_line_array[i]}
|
||||
else
|
||||
v[${g_csvfile_base}_${g_headline_item}_${r}]=${g_csv_line_array[i]}
|
||||
vr[${g_csvfile_base}_${g_headline_item}_${l}]=${g_csv_line_array[i]}
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
((l++))
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
function g_wget {
|
||||
wget -T 10 -t 2 -U "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36" $@
|
||||
wget -T 10 -t 2 \
|
||||
--header="User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" \
|
||||
--header="Content-Type: application/json" \
|
||||
--header="Accept-Language: en-US,en," \
|
||||
$@
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user