How to escape apostrophe in nagios contacts config file - nagios

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.

Related

What is the proper way to escape quotes and slashes when running a Jest test with --collectCoverageFrom from Powershell via npm scripts?

I am a React developer, and am used to running commands like the example below from Bash in Linux, but now I have to make it work in a Windows environment from Powershell:
npm test ExampleComponent --collectCoverageFrom='["**/ExampleComponent.tsx"]' --watch
The npm test script just has "jest" in it, but I need to use it via the script so that I am using the version of jest in the project, not a global.
I use this when trying to fill-in gaps in code coverage in a specific file (ExampleComponent.tsx), so I want Jest to reassess the coverage for just that one file when I save changes to the test file (ExampleComponent.test.tsx in this case).
This is what I ran in Powershell (Added the quotes in "--" because Powershell doesn't treat -- as bash does, and switched from forward slash to backslash for Windows):
npm test "--" ExampleComponent --collectCoverageFrom='["**\ExampleComponent.tsx"]' --watch
This is how jest gets called as per the output from npm:
jest "ExampleComponent" "--collectCoverageFrom=[**\ExampleComponent.tsx]" "--watch"
In Powershell (version 7.2, if that matters), the command above doesn't restrict the coverage check to the specified file. It does only test the specified file, but the collectCoverageFrom option is ignored presumably because the pattern jest receives is mangled by Powershell.
How can I escape the quotes and slashes from a Powershell commandline to replicate the bash invocation at the top? Based on answers regarding escaping in Powershell, I've tried combinations of multiple backslashes and multiple quotes in a myriad of permutations, but none of them have worked so far.
Update as of Powershell version 7.2.1:
The triple-backslash doesn't seem to be necessary anymore; the syntax in this answer's previous version is no longer working for me. But the following works:
npm t "--" ExampleComponent --collectCoverageFrom="'[\""**/ExampleComponent.tsx\""]'"
Jest echoes back the same as before as mentioned below with this syntax.
Previous version:
I have found a version that works:
npm t "--" ExampleComponent --collectCoverageFrom="'[\\\""**/ExampleComponent.tsx\\\""]'"
The command seems to be running as expected, calculating coverage for the specified file only.
Jest echoes back the command as:
jest "ExampleComponent" "--collectCoverageFrom='[\"**/ExampleComponent.tsx\"]'"
The processed version has backslashes before the double-quotes since the entire argument is already wrapped in double-quotes. I also had to change the backslash back to a forward slash.
Thanks to #mklement0 for his input in the question's comments.
Your solution is effective, but let me add important background information:
The core problem is the sad reality that up to at least PowerShell 7.2 an extra, manual layer of \ -escaping of embedded " characters is required in arguments passed to external programs. This may get fixed in a future version, which may require opt-in. See this answer for details.
In your particular case, the problem is apparently compounded by having to perform this escaping twice, because two calls are involved: first, to npm, which then relays some of the arguments it received to jest.
Ultimately, what you want jest to see verbatim, after it has parsed its own command line (on Windows) is the following string:
--collectCoverageFrom='["**/ExampleComponent.tsx"]'
As an aside: Your bash command does not achieve that, because the ' have syntactic function (as they do in PowerShell) and are removed by bash before the resulting string is passed on.
If the PowerShell bug weren't in the picture, you'd use the following:
npm t '--' ExampleComponent --collectCoverageFrom='''["**/ExampleComponent.tsx"]'''
Note the '' embedded in the overall '...' verbatim string, which are escaped ' chars. to be included verbatim in the string.
Alternatively, you could use "..." for the outer quoting, which then requires you to escaped the embedded " chars. as `" (or ""[1]):
npm t '--' ExampleComponent --collectCoverageFrom="'[`"**/ExampleComponent.tsx`"]'"
Note, however, that such double-quoted strings are expandable strings, i.e. subject to string interpolation. It's generally better to use verbatim strings ('...') for strings that do not require interpolation, for conceptual clarity and to prevent potentially unwanted interpolation (not a concern here, given that the string contains no meant-to-be verbatim $ or `characters).
With no bug regarding embedded " characters present, there is also no problem with relaying arguments - irrespective of the number of times this is performed.
In fact, if you're on PowerShell 7.2, you can make this work, but only if you explicitly enable the PSNativeCommandArgumentPassing experimental feature:
Enable-ExperimentalFeature PSNativeCommandArgumentPassing
Then start a new session for the change to take effect.
In the new session, run $PSNativeCommandArgumentPassing = 'Standard' so as to also apply the fix to batch files (*.cmd, *.bat), which is necessary because the npm CLI is implemented as one.
This unfortunate need for an additional, per-session step is the result of a highly unfortunate design decision to by default (value 'Windows') exempt batch files and WSH script files (JScript, VBScript) from the fix, instead of applying target scripting engine-appropriate fixes automatically - see the conversation in GitHub issue #15143
Run Disable-ExperimentalFeature PSNativeCommandArgumentPassing later to disable it again.
With the bug present:
The embedded " characters in your string require manual \-escaping, due to the bug - irrespective of whether you use a '...' or a "..." string:
If only one call were involved, this means:
# Note the \-escaped "
npm t '--' ExampleComponent --collectCoverageFrom='''[\"**/ExampleComponent.tsx\"]'''
This would make npm see the desired verbatim string.
Because npm then relays the argument in question to jest, an additional round of escaping must be applied:
# Note the \-escaped ", preceded by an \-escaped \
npm t '--' ExampleComponent --collectCoverageFrom='''[\\\"**/ExampleComponent.tsx\\\"]'''
That is:
The call to npm effectively turns the \" to "
Because the argument is then relayed it must again be manually \-escaped, so that the " chars. are also preserved in the call to jest.
By prepending \\ - i.e. an escaped \ to - \" (\\\"), npm ends up seeing verbatim \", which, when relayed via PowerShell, makes jest see just ", as desired.
[1] While "" works fine inside "...", it works only there. By contrast, `" uses PowerShell's general escape character, the backtick (`) - and having to remember only that one character, irrespective of context, reduces the memory burden for the user.

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

filename contains space and wildcard in a variable

I receive files which names contain spaces and change every week (the name contains the week number)
IE, the file for this week looks like This is the file - w37.csv
I have to write a script to take this file into account.
I didn't succeed in writing this script.
If I do :
$FILE="This is the file - w*.csv"
I don't find /dir/${FILE}
I tried "This\ is\ the\ file - w*.csv"
I tried /dir/"${FILE}" and "/dir/${FILE}"
But I still can't find my file
It looks like the space in the name needs the variable to be double-quoted but, then, the wildcard is not analysed.
Do you have an idea (or THE answer)?
Regards,
Olivier
echo /dir/"This is the file - w"*.csv
or — you almost tried that —
echo /dir/This\ is\ the\ file\ -\ w*.csv
Use a bash array
v=( /dir/This\ is\ the\ file - w*.csv )
If there is guaranteed to be only one matching file, you can just expand $v. Otherwise, you can get the full list of matching files by expanding as
"${v[#]}"
or individual matches using
"${v[0]", "${v[1]}", etc
First of all, you should not use the dollar sign in an assignment.
Moreover, wildcard expansion is not called in an assignment. You can use process substitution for example, though:
FILE=$(echo 'This is the file - w'*.csv)
Note that the wildcard itself is not included in the quotes. Quotes prevent wildcard expansion.

Querying backslash

I am trying to query a table that has strings with backslash (/). For example strings are:
test
test/test
test4
test5
When I use wild char I do not get "test/test" in the result set. I searched web for including backslash in queries, but couldn't find a solution. Does any one have any idea about this issue?
EDIT:
it is a simple query like:
SELECT * FROM aTable;
I believe that you should escape backslashes. I've needed to do it when I used PHP's echo statement.
You can escape backslashes by typing a backlash before the backslash you want to escape
Like: \\
You might want to also add backticks to the table name
`aTable`, or there;s a chance that it won't work.

escaping dash in username

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";

Resources