SQLITE3 --- Strange behaviour result between small script and large script

I made a test on sqlite3. I write a main small script which source a function script, then call a function which search data in a database.

Main script is : 1 - Small script
https://paste.opensuse.org/pastes/e60f325c403e

Function script is : 2 - Function script
https://paste.opensuse.org/pastes/0d82828da3fc

The good return result is :

removed '/tmp/TMP_SQLITE/temp30'

#
# --- using : test_115-a_list_all_func.sh
# --- using : SCRIPT_NAME : 01-script_install_master_sys_config_script.sh
# --- using : outout      : /tmp/TMP_SQLITE/temp30
#


cat /tmp/TMP_SQLITE/temp30
1|01-script_install_master_sys_config_script.sh
.
FINISHED

Now in a larger bash application (30 bash scripts) I added the function used in my test in a script sourced by the main script. I added a call to the function in one of the other script.
I call the function the same way it is written in my test.

I did not get a result, and did not get no error.

CALLING : _TEST_SQLITE_
TMP_SQLITE_DIR : /tmp/TMP_SQLITE
.
rm: cannot remove '/tmp/TMP_SQLITE/temp30': No such file or directory

#
# --- _TEST_SQLITE_
# --- using : DATABASE_LOGGER : /run/media/user_install/NVIDIA_OPTIMUS/30_SQLITE/DATALOGGER/NVIDIA_OPTIMUS_DATALOGGER.db
# --- using : SCRIPT_NAME_2   : 01-script_install_system_config_script.sh
# --- using : output          : /tmp/TMP_SQLITE/temp30
#


cat /tmp/TMP_SQLITE/temp30
RET_CODE : 0

I have no idea where to search.

Any search directions are welcome.

Trace your script and find out what it does.

using strace ?

Using set -x or bash -x or sh -x - whatever it more convenient and appropriate.

The directory "$TMP_SQLITE_DIR/temp30" is either not created or it is already deleted. before the function was executed. At any rate add a test before running a destructive command such as rm. In a scenario that the variable is empty then rm would run:

rm -v /temp30

Instead of

rm -v “$TMP_SQLITE_DIR/temp30”

Which Is what exactly happen to a script that was written by some developer (nvidia installer iirc) but the variable was empty in some cases. Long story short it deleted the / directory or some parts of it. Debugging and logging the output somewhere should be a start.

Oups.
I did not imagine that this could happen to me.
Thank you for bringing me back to the real world.

I did use set -x.

My problem is in this part of code :

sqlite3 "$DATABASE_LOGGER" << EOF
.output "$TMP_SQLITE_DIR/temp30"
select id,SCRIPT_NAME from datalogger where SCRIPT_NAME = '$A_SCRIPT' ;
EOF

I did not get any data in the file pointed by

.output

I did not get any error.

For the moment I have bypassed the problem using the following syntax:
sqlite3 "$DATABASE_LOGGER" 'select id,SCRIPT_NAME from datalogger where SCRIPT_NAME = '''"'$A_SCRIPT'"''' ;' > "$TMP_SQLITE_DIR/temp30"

But I would like to know why the first syntax does not work.

It works for me in trivial testing so the syntax is correct.

That was a Bumblebee incident… /usr from memory…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.