escaping dash in username - database

I'm having difficulty modifying a postgres user that contains a dash in its name - I've run into this problem several times, but can never find the answer (no matter how much googling I do!).
osm=# grant all on osm_polygon_view to www-data;
ERROR: syntax error at or near "-"
LINE 1: grant all on osm_polygon_view to www-data;
^
I have tried just about every permutation of escape characters and quotes, and still can't get this to work. I have also encountered this when trying to change www-data password.

Double quotes is what you should use - not single quotes.
grant all on osm_polygon_view to "www-data";

Related

How do i move files with a batch file?

I have tried creating a batch file that moves mods from the gta v directory to another when i need to play online. I wrote this so far:
move E:/Epic Games/GTAV/TrainerV.asi C:/Users/example/Desktop
I got this error:
The syntax of the command is incorrect.
Can someone tell me how to do it right? I would appreciate it.
To be able to operate with any file with a space in cmd/batch, you need to group them with quotes "" and since
E:\Epic Games\GTAV\TrainerV.asi
^ Here
has spaces, you need to surround it with quotes. A good practice is to have quotes anyways. The correct syntax is:
move "E:\Epic Games\GTAV\TrainerV.asi" "C:\Users\example\Desktop"
You have multiple issues with your current command.
First, paths containing spaces must be surrounded in double quotes.
Second, Windows uses the backslash \ instead of the forward slash / as the path separator. While the forward slash might be accepted in some cases, it won't work in all, so it's better to use the proper \.
The corrected version of your code would be
move "E:\Epic Games\GTAV\TrainerV.asi" C:\Users\example\Desktop

How to escape apostrophe in nagios contacts config file

There is a user with apostrophe in their name.
Nagios documentation says that semicolon, apostrophes and quotation marks should be avoided but it doesn't provide info about how to escape one if it is name.
I have tried \' , \\', "someo'name", "someo\'name" etc but nagios checkconfig fails every time.
Please let me know what else I need to do.

How to write a full path in a batch file having a username with spaces?

Essentially I am referencing a path in my batch file that includes the username.
Here is what I mean:
C:/users/%username%/
Using %username% does seem to work when refrecning the user currently logged in to the machine, but fails if the username has a space. For example the username jlows works no problem, but j lowes does not and shows an error saying user "j" cannot be found.
What can be added to the path to account for this situation?
Always quote paths in batch files. This way, it helps you in order to avoid misbehaviours like this one. In most of the cases, system considers, e.g. the path random which doesn't exist because you have entered random test.
So, replacing / with \ as this is the default Windows separator, will give you:
"C:\Users\%username%"
However, there is a shorter version, userprofile, which stands for C:\Users\%username%, exactly what you have. Use it like:
"%UserProfile%"

"Invalid SHA1 hash format" error calling signtool from msbuild or command line

I am trying to sign my assemblies and setup files during project build using SignTool.exe. Following this answer I wanted to use the /sha1 option so that I don't need to specify the certificate password. However, when I do this I am getting an "Invalid SHA1 hash format" error. I have tried both from an MSBuild Exec task, from a Visual Studio Developer Command prompt and from a batch file all with the same error.
The command I'm trying is (obviously with a different key):
signtool.exe sign /a /sha1 ‎1234567890abcdef1234567890abcdef12345678 /tr http://timestamp.comodoca.com /td SHA256 /v Setup.msi
I think my certificate is installed correctly and the SHA1 key is correct as it works with the SignFile MSBuild task correctly. I'd just use that but I also need to be able to sign my installer files which aren't built with MSBuild and hence need to be signed from a batch script.
So what could be the problem and how do I fix it?
I had the same problem and found out that there might be a hidden UNICODE character which causing this error. Just copy the text to a new Notepad instance and back and it will work.
Alternatively, place the cursor in this location:
/sha1 <cursor>abcdefg
Then press BACKSPACE. If you have to press BACKSPACE twice to get the cursor next to the "/sha1" directive, there was an invisible character. Then just type space and you are done.
Stupid mistake and I can't believe it took so long to realise. I had an extra space character before the thumbprint string which was the cause of the error.
Even after fixing that though I then got another error:
No certificates were found that met all the given criteria.
Running the command again with the /debug option listed all of the certificates it attempted to use and
After Hash filter, 0 certs were left.
The hash SHA1 hash for the certificate I wanted to use was exactly the same as I specified with the only exception being that the hash was all in upper-case letters. So tried the command again with the hash in all upper-case letters and... it worked.
As I haven't seen this requirement documented anywhere I thought I'd provide the answer here.
I solved it by providing the thumprint in the build command itself as follows:
msbuild /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:PackageCertificateThumbprint=897C9032E6BD06D32A315173D09C93B06CBDE1B4
remove the thumbprint from .csproj it should look like this.
<PackageCertificateThumbprint></PackageCertificateThumbprint>

My batch script is reporting an error stating "was unexpected at this time"

The Windows batch file I am trying to run contains the following assignment:
set ANT_HOME="C:/Program Files/apache-ant-1.8.4"
The offending line is:
call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
And when I run the script with echo on I get:
call "C:/Program_Files/apache-ant-1.8.4"/bin/ant -f ../config/common.xml start_db
Files/apache-ant-1.8.4""=="" was unexpected at this time.
I've moved the second quote to to the end of the path, after the ant, but I receive the same error message.
If ant were an .exe I would say your code should work. But I suspect that ant is a batch file, and the error is occurring within the ant script.
I base my conclusion on your error message - specifically the following portion of it: ""=="". The error message is a batch parsing error, and I don't see how your code could generate those characters. So I figure ant must be a batch script that is causing the problem.
I suspect ant.bat has #echo off at the top, so you are not seeing the actual line that is failing.
Not having access to the ant.bat script, I couldn't possibly diagnose exactly what is failing, nor can I guess on how to fix it.
Update - exact problem found
I found a copy of ant.bat online.
It has the following line of code within:
if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
Your definition of ANT_HOME includes enclosing quotes, so the code is trying to execute
if ""C:/Program Files/apache-ant-1.8.4""=="" set ANT_HOME=%DEFAULT_ANT_HOME%
The space is not quoted, and you have your error.
All you need to do to fix everything is to remove the quotes from the definition of ANT_HOME, and then add quotes to your CALL statement:
set "ANT_HOME=C:/Program Files/apache-ant-1.8.4"
call "%ANT_HOME%/bin/ant" -f ../config/common.xml start_db
Forward-slashes are not always reliable as folder delimiters within Windows. See Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?.
Better to use back-slashes.
set "ANT_HOME=C:\Program Files\apache-ant-1.8.4"
call "%ANT_HOME%\bin\ant" -f ..\config\common.xml start_db
The quotes have to completely surround a file name. You can't use them for partial names. Try this instead:
set ANT_HOME=C:\Program Files\apache-ant-1.8.4
call "%ANT_HOME%\bin\ant" -f ../config/common.xml start_db
Oh, and I changed some of your slashes to backslashes (DOS doesn't like forward slashes). I assume you are allowed to use / in that parameter you are passing though.

Resources