You are deep in quoting hell there.
Your find
command passes to sh -c
an argument like
mkdir -p "$(dirname /mnt/data/test/20220508/mnt/data/abc/def.log)";touch /mnt/data/test/20220508/mnt/data/abc/def.log; du -S /mnt/data/abc/def > /mnt/data/test/20220508/mnt/data/abc/def.log; awk -F'\t' '{print "INSERT INTO DATE20220508(folder_size, folder_location) VALUES('$1', '$2');"}' /mnt/data/test/20220508/mnt/data/abc/def.log
Now sh
parses this, removing one quoting level. It expands the $(dirname /mnt/data/test/20220508/mnt/data/abc/def.log)
to /mnt/data/test/20220508/mnt/data/abc
, and the variables $1
and $2
in the awk
to empty strings (since it didn't receive any positional parameters), giving
mkdir -p /mnt/data/test/20220508/mnt/data/abc;touch /mnt/data/test/20220508/mnt/data/abc/def.log; du -S /mnt/data/abc/def > /mnt/data/test/20220508/mnt/data/abc/def.log; awk -F\t '{print "INSERT INTO DATE20220508(folder_size, folder_location) VALUES(, );"}' /mnt/data/test/20220508/mnt/data/abc/def.log
(I reinserted the single quotes around the awk
program text argument for clarity.)
The easiest way out is to create a file for the awk
program which you then pass to awk
via the -f
option. I would then also recommend doing the assignment FS = "\t"
in that file instead of using the -F
option.
Finally, if you don't have any further use for the log files except for creating the SQL statements, you can simplify your script considerably by piping the output of du
directly to awk
, like:
DT=`date +"%Y%m%d"`
find /mnt/data -maxdepth 2 -mindepth 2 -type d -exec sh -c 'du -S {} | awk -v DT='$DT' -f /mnt/data/makeinserts.awk' \;
with the file /mnt/data/makeinserts.awk
containing the pure awk
program:
BEGIN{FS="\t"}
{print "INSERT INTO DATE"DT"(folder_size, folder_location) VALUES('"$1"', '"$2"');"}