Reputation: 3
I have a shell script using variable assignments to hold values for comparison within if statements. These variables are generated via SQL statements. I put in echo's for debugging to confirm the location of the creations but I'm unsure what's causing these statements to create the directories.
It's a loop through several databases looking for the "new" values to be added. What I've found is when there are new values, the files appear as the numbers. Today's runs look as follows because we have no new records to add:
-rw-r--r-- 1 bkp nz 0 Sep 03 16:19 0
-rw-r--r-- 1 bkp nz 0 Sep 03 16:19 2394
The code portion giving me an issue is as follows (calls #!/bin/sh at top of script) and exists in a while loop that loops through a database list to search:
COUNT_NEW=`${NZUTL_BIN}/nzsql -host ${DB_HOST} -db ${DB_LOOP} -u ${DB_USER} -pw ${DB_PASSWD} -A -t -c "select count(*) from tmp_retention_driver"`
echo "COUNT_NEW now equals ${COUNT_NEW}"
COUNT_OLD=`${NZUTL_BIN}/nzsql -host ${DB_HOST} -db tmpdb01 -u ${DB_USER} -pw ${DB_PASSWD} -A -t -c "select count(*) from new_retention_driver"`
echo "COUNT_OLD now equals ${COUNT_OLD}"
if [ "${COUNT_NEW}" > 0 ]; then
echo "Inserting ${COUNT_NEW} records from ${DB_LOOP}"
${NZUTL_BIN}/nzsql -host ${DB_HOST} -db tmpdb01 -u ${DB_USER} -pw ${DB_PASSWD} -A -t -c "insert into new_retention_driver (tablename, owner, createdate, dbname, status_cd, max_arch_retention) select tablename, owner, createdate, database, 'R', max from ${DB_LOOP}..tmp_retention_driver" -o ${LOG_FILE}/${DB_LOOP}_new_record_inserts.log
COUNT_OLD_UPDATE=`${NZUTL_BIN}/nzsql -host ${DB_HOST} -db tmpdb01 -u ${DB_USER} -pw ${DB_PASSWD} -A -t -c "select count(*) from new_retention_driver"`
echo "COUNT_OLD_UPDATE now equals ${COUNT_OLD_UPDATE}"
Upvotes: 0
Views: 185
Reputation: 780974
The problem is this line:
if [ "${COUNT_NEW}" > 0 ]; then
>
has special meaning in shell commands, it's used for output redirection. In the test
command, the -gt
option is used to perform a greater than comparison. So change it to:
if [ "${COUNT_NEW}" -gt 0 ]; then
Upvotes: 1