I did this
-Dserver.address=hostname -I|cut -f5 -d ' '
in configuration, in "VM Options"
but I got Error
Unrecognized option: -I|cut
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
I need help, please
The reason you get the unrecognised option error is because you use spaces in your JVM argument. You will need to enclose it with quotes. The official JVM docs say:
-Dproperty=value. Sets a system property value. The property variable is a string with no spaces that represents the name of the property. The value variable is a string that represents the value of the property. If value is a string with spaces, then enclose it in quotation marks (for example -Dfoo="foo bar").
So in your example that should be something like:
-Dserver.address="hostname -I|cut -f5 -d ' '"
However I'm not 100% if you are able to use a command as a value. As far as I know it can only be a 'static' value.
Related
I need to update values in a column when the row matches a certain WHERE clause, using the content of a text file.
The content of the file is javascript code and as such it may contain single quotes, double quotes, slashes and backslashes - out of the top of my mind, it could contain other special characters.
The content of the file cannot be modified.
This has to be done via psql, since the update is automated using bash scripts.
Using the following command - where scriptName is a previously declared bash variable -
psql -U postgres db<<EOF
\set script $(cat $scriptName.js))
UPDATE table SET scriptColumn=:script WHERE nameColumn='$scriptName';
EOF
returns the following error
ERROR: syntax error at or near "{"
LINE 1: ...{//...
^
I would like to treat the content of the file $scriptName.js as plain text, and avoid any interpretation of it.
You should quote the variable:
UPDATE table SET scriptColumn=:'script' WHERE ...
That causes the contents of the variable to be properly escaped as a string literal.
I found a solution to my problem, even though I don't know why it works.
I leave it here in the hope it might be useful to someone else, or that someone more knowledgeable than me will be able to explain why it works now.
In short, setting the variable as a psql parameter did the trick:
psql -U postgres db -v script="$(cat $scriptName.js)"<<EOF
UPDATE table SET scriptColumn=:'script' WHERE nameColumn='$scriptName'
EOF
Not sure how this differs from
psql -U postgres db <<EOF
\set script "$(cat $scriptName.js)"
UPDATE table SET scriptColumn=:'script' WHERE nameColumn='$scriptName'
EOF
which I tried previously and returns the following error:
unterminated quoted string
ERROR: syntax error at or near "//"
LINE 1: // dummy text blahblah
Thanks to everybody who helped!
FYI: I am using Intellij's 'Run/Debug Configurations' tool.
I would like to pass an empty string as a property to my app via the command line:
--spring.ldap.username=
I have tried:
--spring.ldap.username= # results in parse error
--spring.ldap.username=''
--spring.ldap.username="" # results in parse error
--spring.ldap.username=\"\"
The attempts that actually parsed successfully yielded incorrect values, as demonstrated when I try to print the 'empty' Strings:
System.out.println(environment.getProperty("spring.ldap.username"));
// returns:
// ''
// ""
Setting the same property to an empty string in the application.properties file works perfectly:
spring.ldap.username=
The same print statement:
// returns:
//
// ^^ totally empty string
Is there a trick I am missing?
Try this: --spring.ldap.username (if you leave the =, it will parse as null)
So as it turns out, this can be accomplished by using regular JVM arguments.
Instead of
--my.property=
use
-Dmy.property=
Native JVM arguments are able to accept empty Strings I guess.
In IntelliJ, you can add them in the respective fields in the Run/Debug Configurations window as shown below:
This answer to another question also has some more information on passing JVM arguments to Spring applications.
I'm trying to fill some parameters using Command Line build step.
Here is the code:
#!/bin/bash -x
VERSIONCODE=123
VERSIONNAME=1.2.0
echo "##teamcity[setParameter name='env.VERSION_NAME' value='$VERSIONNAME']"
echo "##teamcity[setParameter name='env.VERSION_CODE' value='$VERSIONCODE']"
Build Log:
[09:14:06][Step 1/8] + VERSIONCODE=123
[09:14:06][Step 1/8] + VERSIONNAME=1.2.0
[09:14:06][Step 1/8] + echo '
[09:14:06][Step 1/8] ##teamcity[setParameter name='\''env.VERSION_NAME'\'' value='\''1.2.0'\'']
[09:14:06]
[Step 1/8] Incorrect property name.
Valid property list format is (name( )*=( )*'escaped_value'( )*)* where escape symbol is "|"
[09:14:06][Step 1/8] '
[09:14:06][Step 1/8] + echo '
[09:14:06][Step 1/8] ##teamcity[setParameter name='\''env.VERSION_CODE'\'' value='\''123'\'']
[09:14:06]
[Step 1/8] Incorrect property name.
Valid property list format is (name( )*=( )*'escaped_value'( )*)* where escape symbol is "|"
[09:14:06][Step 1/8] '
I've been trying to google it for several hours and got nothing.
what am I doing wrong?
The -x bash option is pretty useful and the solution need not involve removing that option. Instead, let's see why the problem occurs in the first place in custom scripts.
With bash's -x option, bash will echo the line it's about to execute, including literal escape chars. TeamCity will try to parse this output (which we don't want at this point as the command line echo isn't meant to be parsed). If TC sees the echoed command line as malformed (e.g., because of the escape chars), it will emit an Incorrect property name. warning:
echo "##teamcity[buildStatisticValue key=\'warnings\' value=\'42\']"
However, TC will see the executed output of that command as fine.
If TC parses an echoed command line correctly as a TC message, it's even worse because it will then parse it again when that line executes, potentially leading to double-counting and other subtle errors.
Instead, if you must have ## in your custom script and -x is enabled, just be sure to escape the two hashes like so:
echo \#\#teamcity[buildStatisticValue key=\'warnings\' value=\'42\']
Bash will print the exact command line with the escaped hashes and TC won't try to parse it (and either fail or double-count), but when the line is executed it will echo as ##teamcity[buildStatisticValue key='warnings' value='42' which TC will parse as intended.
I've asked it on teamcity-support.jetbrains.com and got an answer:
The issue is with the "-x" from the script definition. It seems to go
to extra lengths for tracing the script, which ends in the script
failing. Removing the -x will make the script work properly. You can
verify that the parameters are set at the end of the build by checking
on the build result page, parameters tab.
It works.
I have a Unix variable like below:
emp_tbl=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28
Now I have created another variable like below:
tablename=emp_tbl
Now I want to see the value 1,2,3,... using $($tablename) but I am getting error in it:
~$>emp_tbl=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28
~$>tablename=emp_tbl
~$>echo $($tablename)
-bash: emp_tbl: command not found
You need indirection:
echo ${!tablename}
Read the documentation on shell parameter expansion yet again (reminder to self: do thou likewise).
Your attempt using $($tablename) fails because the $(...) notation is command substitution, and the value in $tablename is interpreted as the command name and the command with the name emp_tbl could not be found.
I'm trying to compile a resource file (.rc) for a Win32 application but I'm getting this error
use "" to put " in a string
Among other things, I'm trying to define a MENUITEM with a string that looks like this "&Save\t\"Alt+S\"". I have tried escaping the " character with "\"" but it still doesn't work.
Why are you escaping it with \" when the resource compiler clearly says you that you must escape it with ""? Just do:
"&Save\t""Alt+S"""