Ansible docker invalid character % - sql

I am writing some ansible to automate my docker deployments.
I am trying to set an env variable to be % but I get this error:
ERROR! Syntax Error while loading YAML.
found character that cannot start any token
The error appears to have been in '/vagrant/roles/zoneminder_docker/tasks/main.yml': line 21, column 24, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
MYSQL_ROOT_PASSWORD: mysqlpsswd
MYSQL_ROOT_HOST: %
^ here
Is there any way to escape this character? As if I exclude this line, my deployment fails.

Is there any way to escape this character? As if I exclude this line, my deployment fails.
The thing you are looking for is to make that value a string literal:
MYSQL_ROOT_PASSWORD: mysqlpsswd
MYSQL_ROOT_HOST: '%'

Related

How to split a large query in command line?

I installed oracle db version 19c in my docker environment and set up a database filled with dummy data. However, when I try to run a very large query I get the error:
SP2-0341: line overflow during variable substitution (>3000 characters at line 1).
I tried splitting it up with linebreaks but depending on how I split it I get all kinds of errors like:
ERROR at line 2: ORA-00933: SQL command not properly ended
or
ERROR at line 2:
SP2-0341: line overflow during variable substitution (>3000 characters at line 3)
The query is formatted as
SELECT AA.n_name AS AA_n_name, AA.n_nationkey AS ...
FROM nation AS AA FULL OUTER JOIN supplier...
WHERE (AC.p_partkey = ... AND...) OR((AC.p_partkey = ...)); -- The where part is over 5000 characters long--
Is there an alternative or solution to tackling this in the command line? I tried running the query as a sql file as well and hit a 4999 limit. I am on a Ubuntu server if that would help and any assistance would be appreciated.
It depends on the environment that you're working in, but generally you are able to continue a command onto the next line by ending the line with a 'back slash' \.

How to use "%" character in sql query on linux shell?

I am trying to pull all the jdk packages installed on set of hosts by sending a sql select statement to osquery on linux shell via pssh .
Here is the query:
pssh -h myhosts -i 'echo "SELECT name FROM rpm_packages where name like '%jdk%';"| osqueryi --json'
but usage of "%" is giving me below error.
Error: near line 1: near "%": syntax error
I tried to escape % ,but the error remains same. Any ideas how to overcome this error?
You aren't getting this error from your shell but from the query parser, and it's not actually caused by the % character, but to the ' that immediately precedes it. Look at where you have quotes:
'echo "SELECT name FROM rpm_packages where name like '%jdk%';"| osqueryi --json'
^----------------------------------------------------^ ^-------------------^
These quotes are consumed by the shell when it parses the argument. Single quotes tell the shell to ignore any otherwise-special characters inside and treat what is within the quotes as part of the argument -- but not the quotes themselves.
After shell parsing finishes, the actual, verbatim argument that gets sent to pssh looks like this:
echo "SELECT name FROM rpm_packages where name like %jdk%;"| osqueryi --json
Note that all of the single quotes have been erased. The result is that your query tool sees the % (presumably modulus) operator in a place that it doesn't expect -- right after another operator (like) which makes about as much sense to the parser as name like * jdk. The parser doesn't understand what it means to have two consecutive binary operators, so it complains about the second one: %.
In order to get a literal ' there, you need to jump through this hoop:
'\''
^^^^- start quoting again
|||
|\+-- literal '
|
\---- stop quoting
So, to fix this, replace all ' instances inside the string with '\'':
pssh -h myhosts -i 'echo "SELECT name FROM rpm_packages where name like '\''%jdk%'\'';"| osqueryi --json'
osqueryi accepts a single statement on the command line. Eliminating the echo can make quoting a bit simpler:
osqueryi --json "SELECT * FROM users where username like '%jdk%'"
You will, however, need the quotes to pass through your pssh command line.
While osqueryi is great for short simple things, if you're building a frequent polling service, osqueryd with scheduled queries is generally simpler.

Unexpected error running Liquibase: Unexpected value [...] (options must start with a '--') && howTo? diff w/ properties file

I'm trying to diff two databases from the command line in linux. I'm hoping that someone can tell me what I'm doing wrong... my command is
./liquibase
--driver=com.mysql.cj.jdbc.Driver \
--url=jdbc:mysql://{it'svalid}:3306/db_schema_1?useLegacyDateTimeCcxle=false&serverTimezone=UTC \
--username={it'svalid} \
--password={it'svalid} \
diff \
--referenceUrl=jdbc:mysql://{it'svalid}:3306/db_schema_2?useLegacyDateTimeCcxle=false&serverTimezone=UTC \
--referenceUsername={it'svalid}
--referencePassword={it'svalid} \
--changeLogFile=databaseChangeLog.sql
I'm getting this in response:
java -cp
".:/home/someguy/needit/liquibase/liquibase.jar:/home/someguy/needit/liquibase/lib/:/home/someguy/needit/liquibase/lib/jcl-over-slf4j-1.7.25.jar:/home/someguy/needit/liquibase/lib/jul-to-slf4j-1.7.25.jar:/home/someguy/needit/liquibase/lib/log4j-over-slf4j-1.7.25.jar:/home/someguy/needit/liquibase/lib/logback-1.1.jar:/home/someguy/needit/liquibase/lib/logback-classic-1.2.3.jar:/home/tkrueger/needit/liquibase/lib/logback-core-1.2.3.jar:/home/someguy/needit/liquibase/lib/mysql-connector-java-8.0.15.jar:/home/someguy/needit/liquibase/lib/slf4j-api-1.7.25.jar:/home/someguy/needit/liquibase/lib/snakeyaml-1.18.jar" liquibase.integration.commandline.Main
"--driver=com.mysql.cj.jdbc.Driver
--url=jdbc:mysql://{it'svalid}:3306/db_schema_1 --username={it'svalid} --password={it'svalid} diff --referenceUrl=jdbc:mysql://{it'svalid}:3306/db_schema_2 --referenceUsername={it'svalid} --referencePassword={it'svalid} --changeLogFile=databaseChangeLog.sql" Starting Liquibase at Thu, 02 May 2019 14:21:56 CDT (version 3.6.3 built at 2019-01-29 11:34:48) To
display the help, please pass the '--help' option on the command line.
Unexpected error running Liquibase: Unexpected value
'"--driver=com.mysql.cj.jdbc.Driver' (options must start with a '--')
liquibase.exception.CommandLineParsingException: Unexpected value
'"--driver=com.mysql.cj.jdbc.Driver' (options must start with a '--')
at liquibase.integration.commandline.Main.parseOptions(Main.java:778)
at liquibase.integration.commandline.Main.run(Main.java:185)
at liquibase.integration.commandline.Main.main(Main.java:137)
I've dumped most of the parameters into a liquibase.properties file, to no avail... I thought I found someone else dealing with the leading doublequote on the rejected parameter string (i.e., it appears to be parsing the parameters as "-- instead of simply --), but I'm struggling to understand how to get around that while doing a diff, by putting all my parameters into a liquibase.properties file.
You should check what end of line you have. I had same problem. Resolution was to change from windows eol to linux.

Using sql within shell script

I am currently trying to integrate an sql statement into a shell script, But facing major syntax issue:
My statement in the script:
su - <sid>adm -c 'hdbsql -U SYSTEM export "'SCHEMA'"."'*'" as binary into "'Export Location'" with reconfigure'
I get the following error:
* 257: sql syntax error: incorrect syntax near "*": line 1 col 16 (at pos 16) SQLSTATE: HY000
Would really appreciate if anyone could help me with this.
Thanks and Regards,
AK
Your command line doesn't make much sense to me. It starts with
su - <sid>adm
which means that you are redirecting the contents of the file "sid" into "su" and then redirecting the result of that operation into the file "adm".
Second problem is that in the command you are giving to adm, the single quotes end right before the "" which means, that the "" will get interpreted by the shell as a file glob:
-c 'hdbsql -U SYSTEM export "'SCHEMA'"."'*'" as binary into "'Export Location'" with reconfigure'
You'll need to escape those single quotes like this: "\'".
But I think your problem solving approach is not good. Try to reduce to problem and only then start adding additional things to it. So first try to execute the SQL statement from the "hdbsql" shell. Does it work?
$ hdbsql
> YOUR SQL STATEMENT HERE
Once that works, try to execute the SQL statement from the unix shell as a user:
$ hdbsql -U SYSTEM export ...
Once that works, try to execute it via su
$ su - ...

hide error messages in dcl script

I have a test script I'm running that generates some errors,shown below, I expect these errors. Is there anyway I can prevent them from showing on the screen however? I use the
$ write sys$output
to display if there is an expected error.
I tried to use
$ DEFINE SYS$ERROR ERROR.LOG
but this then changed my entire error output log to this, if this is the correct way to handle it can I unset this at the end of my script somehow?
[error example]
%DCL-E-OPENIN, error opening TEST$DISK:[AAA]NOTTHERE.TXT; as input
-RMS-E-FNF, file not found
%DCL-E-OPENIN, error opening TEST$DISK:[AAA]NOTTHERE.TXT; as input
-RMS-E-FNF, file not found
%DCL-W-UNDFIL, file has not been opened by DCL - check logical name
DEFINE/USER creates a logical name that disappears when the next image exits.
So if you use that just before a command just to protect that command, then fine.
Otherwise I would prefer SET MESSAGE to control the output.
And of course yoy want to grab $STATUS and verify it after the command for success or for the expected error, reporting any unexpected error.
Better still... if you expect certain error conditions to occur,
then why not test for them?
For example:
$ file = F$SEARCH("TEST$DISK:[AAA]NOTTHERE.TXT")
$ IF file.NES."" THEN TYPE 'file'
Cheers,
Hein
To suppress Error message inside a script. try this command
$ DEFINE/USER SYS$ERROR NL:
NL: is a null device, so you don`t see any error messages displayed on your terminal.
good luck
This works interactively and in batch.
$ SET MESSAGE /NOTEXT /NOSEV /NOFAC /NOID
$ <DCL_Command>
$ SET MESSAGE /TEXT /SEV /FAC/ ID