简体   繁体   中英

Run sql query from If else block in shell script

I want to connect sql db and execute sql query from shell script. I tried using this

if float_cmp "$size1 > 7.50"; then
    echo "### THE DATA SIZE IS GREATER THAN 7.5 GB ###"
    echo "############### DROPPING CREATED $IMPUSER USER ###########################"
    ${PATH_TO_CLIENT}sqlplus $EXPUSER/$EXPPWD@$ENDPOINT<< EOF
    drop user $IMPUSER cascade;
    exit;
    EOF
    exit 1
else
    echo "### THE DATA SIZE IS OKAY ###"
fi

The statement is working outside if block but throwing error when executing in IF block

line 80: warning: here-document at line 72 delimited by end-of-file (wanted `EOF')
line 81: syntax error: unexpected end of file

Can anyone please tell what am I doing wrong and what is the solution?

Try removing the indentation inside of the here-document:

if float_cmp "$size1 > 7.50"; then
    echo "### THE DATA SIZE IS GREATER THAN 7.5 GB ###"
    echo "############### DROPPING CREATED $IMPUSER USER ###########################"
    "${PATH_TO_CLIENT}"sqlplus $EXPUSER/$EXPPWD@$ENDPOINT<< EOF
drop user $IMPUSER cascade;
exit;
EOF
    exit 1
else
    echo "### THE DATA SIZE IS OKAY ###"
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM