Understanding Shell Conditional Expressions

Asked 1 months ago, Updated 1 months ago, 3 views

#!/bin/sh

# variable setting
export BATCH_E=$(cd$(dir$0)/..&pwd)
source$BATCH_E/bin/conf/batch.conf

# Batch processing type
TYPE='25'

# Launching the JAVA
$SH_COMMAND $BATCH_RUNNER_SH batch.Dataupd $TYPE"[email protected]"
RESULT = $?
if [$GOODSTABLE.reg_dm<to_char(current_timestamp+'-6 months', 'yyyymmddh24miss');
 ];then
    delete
fi
exit$?

Objective: I would like to write to the shell the process of collectively deleting old historical information after a certain period of time.
Conditions: Delete Generated 6 Months Before Current Time

The csv files are linked once a day.The csv file is registered in the GOODSTABLE table.I'd like to delete linked data from 6 months ago in the shell.
How to access the GOODSTABLE table from the shell and delete data from the shell
I looked into the method, but I couldn't find a way to delete it.I don't know how to execute the following conditions on the shell.

GOODSTABLE.reg_dm<to_char (current_timestamp+'-6 months', 'yyyymmddh24miss');

I think I need to check the sql value for the above conditions.
In that case,

select*fromGOODSTABLE;
if [GOODSTABLE.reg_dm<to_char(current_timestamp+'-6 months', 'yyyymmddh24miss');]
then
delete
fi

Is it possible to write like above to access sql?

postgresql shellscript

2022-09-30 11:16

1 Answers

to_char is probably a function of Oracle, but it cannot be called directly from within the shell script.
I think you will just call the SQL program itself and receive its exit status and output results.

For example, with Oracle, you can use the SQL*Plus command to store the required results in shell variables.

reference:
[Oracle] Store SQL*Plus returned results in Shell variables

#!/bin/sh

variable=`sqlplus-s/asysdba<<EOF
set head off;
select sys_context('USERENV', 'MODULE') from dual;
exit;
EOF
`
echo${variable}

exit0


2022-09-30 11:16

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.