From 00ea4ef63d442b1b7c4e91cc2648bf1661658b01 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Mon, 15 May 2023 23:14:39 +0000 Subject: [PATCH] Fixed issue loading files into webcron.db. Had to add $"..." to the section loading the file in to ensure it didn't try loading the bash variables & functions, etc causing the script to fail --- Scripts/update-database.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Scripts/update-database.sh b/Scripts/update-database.sh index 4704072..2e203e0 100755 --- a/Scripts/update-database.sh +++ b/Scripts/update-database.sh @@ -1,5 +1,6 @@ #!/usr/bin/bash -[[ -f ~/.bashrc ]] && . .bashrc + +[[ -f ~/.bashrc ]] && . ~/.bashrc declare -a crontab_dirs=( /etc/cron.d @@ -7,11 +8,10 @@ declare -a crontab_dirs=( /etc/cron.hourly /etc/cron.weekly /var/spool/cron -) - +) declare -a crontabs_in_db -sqlite_cmd='sqlite3 $WEBCRON_DB' +sqlite_cmd="sqlite3 $WEBCRON_DB" for name in $( $sqlite_cmd <<< "SELECT crontab_path FROM crontabs;"); do @@ -27,11 +27,11 @@ for dir in ${crontab_dirs[@]}; do # path is already stored in the DB # if not it will create one and it will be be indexed in the DB if [[ -f $file ]] && [[ ! "${crontabs_in_db[@]}" == *$file* ]]; then - $sqlite_cmd <<< " + $sqlite_cmd " INSERT INTO crontabs (crontab_path, crontab_data) VALUES ('$file', - '$(<$file)') - " + '$($"$(<$file)")'); + " fi done fi @@ -47,13 +47,13 @@ while read crontab_id crontab_path; do # this will check to make sure that the file exists on disk and # will compare the disk and db versions of the file to make sure if a change is needed to be # loaded into the db. - if [[ -f $crontab_path ]] && [[ ! "$data" == "$(<$crontab_path)" ]]; then - sqlite3 $WEBCRON_DB <<<" - UPDATE crontabs SET crontab_data = '$(<$crontab_path)' WHERE crontab_id = $crontab_id + if [[ -f "$crontab_path" ]] && [[ ! "$data" == "$(<$crontab_path)" ]]; then + sqlite3 $WEBCRON_DB " + UPDATE crontabs SET crontab_data = '$($"(<$crontab_path)")' WHERE crontab_id = $crontab_id " fi done <<< ` sqlite3 $WEBCRON_DB <<< " -SELECT crontab_id crontab_name, crontab_path FROM crontabs; +SELECT crontab_id, crontab_path FROM crontabs; " ` -unset IFS \ No newline at end of file +unset IFS