LiquiBase CLI BASH script not outputting full CLI with ECHO - bash

Hey all I am new to the world of BASHing :)
I am trying to put together this CLI line of code by doing the following:
echo "------"
echo '--url=$URL '\
'--username=$UN '\
'--password=$PW '\
'--referenceUrl=$RURL '\
'--referenceUsername=$RUN '\
'--referencePassword=$RPW '\
'--changeSetAuthor=TD '\
'--diffTypes=tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints '\
'$LIQUI_ACTION'
echo "------"
And the output I am getting is this:
------
--url=$URL --username=$UN
/jenkins/liquibase-3.6.2/liquibase: line 141: --password=$PW : command not found
I can tell right off that its not placing the varibles' value within the cli. Second, I'm not sure why its saying command not found when I am only outputting text? I am just doing the above to make sure all of it is indeed the correct data in the $ and also that it's spaced between each command correctly.
So any help about the above would be great!
UPDATE FOR #RavinderSingh13:
code used:
echo "------"
echo "--url=$URL \
--username=$UN \
--password=$PW \
--referenceUrl=$RURL \
--referenceUsername=$RUN \
--referencePassword=$RPW \
--changeSetAuthor=TD \
--diffTypes=tables, views, columns, indexes, foreignkeys, primarykeys, uniqueconstraints \
$LIQUI_ACTION"
echo "------"

Related

Set csh prompt to raw output of a command with multiple lines and special characters?

I am trying to set my csh prompt to the raw output of a particular command. I know how to do that for simple outputs; for example:
set prompt=`echo propmt%|sed "s/pm/mp/"`
... results in a prompt of:
prompt%
But the prompt I want is more complex. First, it has multiple lines. I know how to do that directly (i.e. not via the output of a command):
set prompt="This is a line\nThis is another\nAnd this is the last% "
... results in:
This is a line
This is another
And this is the last%
But if I try to do that same thing through a command:
set prompt=`echo "This is a line\
This is another\
And this is the last% "`
... the prompt becomes just:
This
... not even This is a line; just This.
On top of that, the specific command that I want to use will output not just multiple lines, but also a bunch of other characters that I assume csh and/or set will interpret in ways that I don't intend. Specifically:
cowsay -f ghostbusters "BOOOOOOOOOOOOOOOOOOOOOOOOO \
? \
? You are using CEEEEEE SHELLLLLLLLLLLLLLLLL\
? \
? Be my guest, but you have no one to blame but\
? YOURSELLLLLLLLLLLLLLLLLLLLLLF"; echo; echo "% "
... which outputs:
_________________________________________
/ BOOOOOOOOOOOOOOOOOOOOOOOOO \
| |
| You are using CEEEEEE |
| SHELLLLLLLLLLLLLLLLL |
| |
| Be my guest, but you have no one to |
\ blame but YOURSELLLLLLLLLLLLLLLLLLLLLLF /
-----------------------------------------
\
\
\ __---__
_- /--______
__--( / \ )XXXXXXXXXXX\v.
.-XXX( O O )XXXXXXXXXXXXXXX-
/XXX( U ) XXXXXXX\
/XXXXX( )--_ XXXXXXXXXXX\
/XXXXX/ ( O ) XXXXXX \XXXXX\
XXXXX/ / XXXXXX \__ \XXXXX
XXXXXX__/ XXXXXX \__---->
---___ XXX__/ XXXXXX \__ /
\- --__/ ___/\ XXXXXX / ___--/=
\-\ ___/ XXXXXX '--- XXXXXX
\-\/XXX\ XXXXXX /XXXXX
\XXXXXXXXX \ /XXXXX/
\XXXXXX > _/XXXXX/
\XXXXX--__/ __-- XXXX/
-XXXXXXXX--------------- XXXXXX-
\XXXXXXXXXXXXXXXXXXXXXXXXXX/
""VXXXXXXXXXXXXXXXXXXV""
%
That's what I want as my csh prompt. At this point, I feel obligated to note that I am not kidding.
I suppose I could forget about running a command to generate it, and instead just manually converting it to a single-line string that's properly escaped for set prompt, but:
That seems like a pain;
I'd like to be able to quickly and easily change the prompt to similar but different things.
So, I'm hoping for some way to tell set prompt "Just use the raw output of (arbitrary-command); don't interpret any of it as special characters or whatever". Is there a way? Or any alternate suggestions to accomplish what I want? Thanks.
Maybe it's better to use the precmd alias for this:
alias precmd 'cowsay -f ghostbusters << EOF \
line 1 \
\
line 2 \
\
line 3 \
EOF'
From csh(1):
precmd Runs just before each prompt is printed. For example, if one
does
> alias precmd date
then date(1) runs just before the shell prompts for each command.
There are no limits on what precmd can be set to do, but
discretion should be used.
Or you can make it a different file to avoid all the backslashes:
alias precmd 'source ~/cowsay'
# ~/cowsay
cowsay -f ghostbusters << EOF
line 1
line 2
line 3
EOF

Saving a single log file from multiples sh scripts

I have 2 sh scripts that saves log files accordingly, but and I want to create another sh to call them.
They are using a property file that contains 3 log functions
my first sh(bteq.sh) creates a table in my Teradata
#!/bin/bash
source "/valdc_procs/properties/general_config_file"
exec_logs "/valdc_procs/logs/" "BTEQ_VALDC_PROCS"
echo "INFO : Starting table creation"
function exec_btqe (){
bteq<<EOF 2>&1
.logmech LDAP
.LOGON ${ipServerPR}/${userNamePR},${passwordPR};
.SET TITLEDASHES OFF;
.SET WIDTH 2000
.SET SEPARATOR ';'
SELECT 1
FROM DBC.TABLES
WHERE DatabaseName = ''
AND TableName = ''
AND TableKind = 'T';
.IF ACTIVITYCOUNT = 0 THEN .GOTO CreateNewTable;
DROP TABLE ;
.LABEL CreateNewTable;
CREATE MULTISET TABLE xpto AS (
SELECT
...
)
WITH DATA;
.LOGOFF;
.QUIT;
EOF
}
exec_btqe
#it gets the rc of the last command if it's an error
rc_result "Error creating table " "/valdc_procs/logs/" "BTEQ_VALDC_PROCS"
#it logs the process when there were no errors
log_output "/valdc_procs/logs/" "BTEQ_VALDC_PROCS"
exit $rc
my second sh(tdch.sh) export that table to a file
#!/bin/bash
source "/valdc_procs/properties/general_config_file"
exec_logs "/valdc_procs/logs/" "TDCH_VALDC_PROCS"
hadoop jar $TDCH_JAR com.teradata.connector.common.tool.ConnectorImportTool \
-libjars $LIB_JARS \
-Dmapred.job.queue.name=default \
-Dtez.queue.name=default \
-Dmapred.job.name=TDCH \
-classname com.teradata.jdbc.TeraDriver \
-url jdbc:teradata://$ipServer/logmech=ldap,database=$database,charset=UTF16 \
-jobtype hdfs \
-fileformat textfile \
-separator ',' \
-enclosedby '"' \
-targettable ${targetTable} \
-username ${userName} \
-password ${password} \
-sourcequery "select * from ${database}.${targetTable}" \
-nummappers 1 \
-sourcefieldnames "" \
-targetpaths ${targetPaths}
#it gets the rc of the last command if it's an error
rc_result "Error exporting the file " "/valdc_procs/logs/" "TDCH_VALDC_PROCS"
echo "INFO : Moving file from HDFS to the FileSystem"
hdfs dfs -copyToLocal ${targetPaths}/"part-m-00000" ${targetFileSystemPath}/ARQ_VALDC_PROCS_OPBK_$TIMESTAMP
rc_result "Error moving the file " "/valdc_procs/logs/" "TDCH_VALDC_PROCS"
echo "INFO : File Moved Arquivo movido com sucesso"
#it logs the process when there were no errors
log_output "/valdc_procs/logs/" "TDCH_VALDC_PROCS"
exit $rc
This log process is working fine when I run each sh individually, but now I want to have another sh calling them.
But I'm not sure how can I get the rc of their commands(bteq.sh and tdch.sh) and save in a single log file
Not 100% certain I understand your need, but that might solve your question:
#!/bin/bash
logfile="/tmp/somefile.txt"
bteq.sh
status_bteq=$?
tdch.sh
status_tdch=$?
echo "Status bteq: $status_bteq" >"$logfile"
echo "Status tdch: $status_tdch" >>"$logfile"
If you want just the return codes, raw without anyother text, you could do:
#!/bin/bash
logfile="/tmp/somefile.txt"
bteq.sh
echo "$?" >"$logfile"
tdch.sh
echo "$?" >>"$logfile"

how can i run some custom commands in a loop sequentially

There are variables that I need to change and run sequentially within certain codes.For example, the ionex_list variable looks like this and i need to change this in a loop. I have 3 variable files like this and 9 pieces of data in a row (ionex_list,receiver_ids,data_record).
ionex_list data_record
jplg0910.19i.Z ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz
jplg0920.19i.Z ISTA00TUR_R_20190920000_01D_30S_MO.crx.gz
... ...
jplg0980.19i.Z ISTA00TUR_R_20190980000_01D_30S_MO.crx.gz
jplg0990.19i.Z ISTA00TUR_R_20190990000_01D_30S_MO.crx.gz
For example, I need to show ISTA00TUR_R_20190910000_01D_30S_MO.crx.gz as -dataFile in rnxEditGde.py, but I get the error "File: "/y2019/d091" does not exist" and I cannot show the path. these .gz files are a few directories under from the directory I'm working in. Since I couldn't pass the rnxEditGde.py part, I can't see if the codes below work properly.
dir=`pwd`
function pl {
sed -n "$1p" $2
}
for j in {091..099}; do
ids=$(pl $j receiver_ids)
ionex=$(pl $j ionex_list)
dataRecordFile=$(pl $j data_record)
gd2e.py -mkTreeS Trees
sed -i "s/jplg.*/**$ionex**/g" $dir/Trees/ppp_0.tree
rnxEditGde.py -dataFile "/y2019/d${j}/**$dataRecordFile**" -o dataRecordFile.Orig.gz
gd2e.py \
-treeSequenceDir Trees \
-drEditedFile** $dataRecordFile** \
-antexFile goa-var/etc/antennaCalsGNSS/igs14_2038.atx \
-GNSS https://sideshow.jpl.nasa.gov/pub/JPL_GNSS_Products/MultiGNSS_Rapid_Test\
-runType PPP \
-recList **$ids** \
-staDb /goa-var/sta_info/sta_db_qlflinn \
>gd2e.log 2>gd2e.err
done

Issue on concatenating files shellscipt

Sorry, I'm from Brazil and my english is not fluent.
I wanna concatenate 20 files using a shellscript through cat command. However when I run it from a file, all content of files are showed on the screen.
When I run it directly from terminal, works perfectly.
That's my code above:
#!/usr/bin/ksh
set -x -a
. /PROD/INCLUDE/include.prod
DATE=`date +'%Y%m%d%H%M%S'`
FINAL_NAME=$1
# check if all paremeters are passed
if [ -z $FINAL_NAME ]; then
echo "Please pass the final name as parameter"
exit 1
fi
# concatenate files
cat $DIRFILE/AI6LM760_AI6_CF2_SLOTP01* $DIRFILE/AI6LM761_AI6_CF2_SLOTP02* $DIRFILE/AI6LM763_AI6_CF2_SLOTP04* \
$DIRFILE/AI6LM764_AI6_CF2_SLOTP05* $DIRFILE/AI6LM765_AI6_CF2_SLOTP06* $DIRFILE/AI6LM766_AI6_CF2_SLOTP07* \
$DIRFILE/AI6LM767_AI6_CF2_SLOTP08* $DIRFILE/AI6LM768_AI6_CF2_SLOTP09* $DIRFILE/AI6LM769_AI6_CF2_SLOTP10* \
$DIRFILE/AI6LM770_AI6_CF2_SLOTP11* $DIRFILE/AI6LM771_AI6_CF2_SLOTP12* $DIRFILE/AI6LM772_AI6_CF2_SLOTP13* \
$DIRFILE/AI6LM773_AI6_CF2_SLOTP14* $DIRFILE/AI6LM774_AI6_CF2_SLOTP15* $DIRFILE/AI6LM775_AI6_CF2_SLOTP16* \
$DIRFILE/AI6LM776_AI6_CF2_SLOTP17* $DIRFILE/AI6LM777_AI6_CF2_SLOTP18* $DIRFILE/AI6LM778_AI6_CF2_SLOTP19* \
$DIRFILE/AI6LM779_AI6_CF2_SLOTP20* > CF2_FINAL_TEMP
mv $DIRFILE/CF2_FINAL_TEMP $DIRFILE/$FINAL_NAME
I solved the problem putting the cat block inside a function, and redirecting stdout to the final file.
Ex:
concatenate()

badly placed ()'s when creating oracle database link in tcsh

#my code
echo \
'create database link remotec101 \
connect to "os_user" \
identified by "password" \
using ' \
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) \
(HOST=c101) \
(PORT=1521)) \
(CONNECT_DATA=(SID=XE)))';'|sqlplus
I tried to run some sql in this way and it worked. But when creating database link I got error, saying badly placed ()'s
This code is in tcsh.
Please help me.
Thanks
The parentheses are not quoted, so they're treated as shell metacharacters.
This:
echo \
'create database link remotec101 \
connect to "os_user" \
identified by "password" \
using \
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) \
(HOST=c101) \
(PORT=1521)) \
(CONNECT_DATA=(SID=XE)));' | sqlplus
will feed the following to the sqlplus command:
create database link remotec101
connect to "os_user"
identified by "password"
using
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=c101)
(PORT=1521))
(CONNECT_DATA=(SID=XE)));
But a "here document" is probably cleaner:
sqlplus <<'EOF'
create database link remotec101
connect to "os_user"
identified by "password"
using
(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=c101)
(PORT=1521))
(CONNECT_DATA=(SID=XE)));
'EOF'
If you want the last 4 lines to become a single line of input to sqlplus, I think you'll need to put them all on one line in your script. Or you might find it easier to use the printf command to organize your output, for example:
printf '%s\n%s\n%s\n%s\n%s %s %s %s\n' \
'create database link remotec101' \
'connect to "os_user"' \
'identified by "password"' \
'using' \
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)' \
'(HOST=c101)' \
'(PORT=1521))' \
'(CONNECT_DATA=(SID=XE)));' | sqlplus
This prints the last 4 lines as a single line. You can adjust the format string as needed.
I figured it out. You have to utilize the fact that tcsh supports both quote types and echo allows multiple arguments:
echo 'create database link remotec101 \
connect to "os_user" \
identified by "password" \
using ' "'" ' ( DESCRIPTION= ( ADDRESS= ( PROTOCOL=TCP )
( HOST=c101 )
( PORT=1521 ) )
( CONNECT_DATA= ( SID=XE ) ) ) ' "';"

Resources