vim -c issue with %s, getting "Illegal variable name" error - vim

I want to perform the below steps on a vim file , but don’t want to do that manually.
I tried using the -c option but getting some error there.
Error which I get
vim file2 -c ":%s/$/|/g" -c ":wq"
Illegal variable name.
What is the error I'am making here ?
Once the above step is done, i want to remove the last | from the file, is there some way for that as well through -c option only?
Regards

Related

CMake appends backslash to command added by add_custom_target

I've a company internal tool which takes multiple files per command line using the following pattern
-i file1 -i file2
To add this tool to my CMake build I've been using the add_custom_target command like this
add_custom_target(
CustomTarget
COMMAND ${CompanyTool} ${FILES} -o output"
DEPENDS ActualTarget)
This works fine as long as FILES only expands to a single one but when I pass in multiple files the command starts to produce only garbage output. Upon inspecting the build.ninja files generated by CMake I found that the custom_target command gets translated to a call where the arguments are followed by backslashes like this
\ -i\ file\
I suspect that's the reason that this ain't working.
Now why the F. does CMake do this and how do I get rid of this behavior?
/edit
Printing the FILES string right before passing it to add_custom_target I can't see those backslashes...
Ok, got it. Building a new list and appending -i and file in a foreach looped worked.
It seems like you didn't create a cmake list variable, but instead created a single valued variable containing a value with multiple spaces. The fact that you don't see the values separated by ;, but by spaces is a clear indication for this. CMake automatically escapes values as necessary to invoke the command with the exact values in the command line:
Wrong:
set(FILES "foo.txt bar.txt baz.txt file with space.txt")
Correct
set(FILES foo.txt bar.txt baz.txt "file with space.txt")
# example command concatenating the file contents
add_custom_target(
CustomTarget
COMMAND ${CMAKE_COMMAND} -E cat ${FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
The cmake generator for Visual Studio converts this to the following command on my system:
"D:\Program Files\CMake\bin\cmake.exe" -E cat foo.txt bar.txt baz.txt "file with space.txt"
(Plus some extra stuff for error handling ect.) Running the command does print the concatenated file contents to the console as expected.
Btw: the single " in output" should actually result in a cmake error. Unless somewhere else there's a corresponding ". If this is not just a copy&paste error it indicates that cmake is doing something other than you expect it to do there.

Keyword argument 'ssh -o ProxyCommand' is not supported by this keyword. Robot framework

I am trying to run the process:
Run Process python ssh -o ProxyCommand='ssh -W %h:%p 10.10.10.10' 10.xxx.xxx.xxx
But am getting below error:
"Keyword argument 'ssh -o ProxyCommand' is not supported by this keyword"
Need help here to run my command
This is from the documentation for Run Process:
Note that possible equal signs in *arguments must be escaped with a backslash (e.g. name\=value) to avoid them to be passed in as **configuration.
So, you need to put a \ before the =:
ssh -o ProxyCommand\=...
You probably also need to remove python , and you also probably need to use shell=True, but that's not related to the question you asked about this specific error message.

GAMESS config script error on bash: syntax error near $<

Error I get is following:
After the new window is open, please hit enter to go on../config: line 82: syntax error near unexpected token newline'
./config: line 82:set reply=$<'
I'm in bash shell. The script was originally meant for csh. I've changed the first line of the script to #!/bin/bash.
The script is supposed to open a new window to enter some variables for configuring.
.
.
.
echo "use the word 'type' to indicate it is a command for the other window."
echo " "
echo -n "After the new window is open, please hit enter to go on."
set reply=$<
tput clear
I've checked and know that the shell is interactive. Instead of executing with sh ./config I tried with bash ./config ; still same error. if I type < in the shell I get the same error. So I figured that make cannot understand '<'
I'm at my wits end googling for the error. Any help is appreciated!
Thanks to meatspace! I abandoned the idea of 'fixing' but just get it running.
What worked was running the script while I'm in tcsh - no edits needed in the script. Since I only needed to set everything for the configuration file it didn't matter how the config script generated the actual installation script.
After that is generated I just switched to bash and everything worked.

scp multiple remote files while entering password once

I'm trying to write a script to copy multiple files (in multiple directories) from a remote host to my local machine.
My script is (more or less) as follows:
path1="/home/db/primary/*.xml"
path2="/tmp/log_*"
copyto="/home/pathtodesktop/Desktop/temp"
mkdir $copyto
scpcommand="scp -o StrictHostKeyChecking=no root#$address:\"$path1 $path2\" $copyto"
echo $scpcommand
$scpcommand
When I run the script, I get the following output:
scp -o StrictHostKeyChecking=no root#SERVER:"/home/db/primary/*.xml /tmp/log_*" /home/pathtodesktop/Desktop/temp
sh: syntax error: unterminated quoted string
cp: cannot stat '/tmp/log_*"': No such file or directory
The output of the echo is as expected. But when I copy the output above and run the command manually in the terminal, it works as expected with no errors.
So the ultimate question is, what am I doing wrong? The command seems to work fine when run manually in the terminal. Where is my syntax error?
Thanks for your help!
Adding set -f will prevent the wildcards in your paths from being expanded locally (although you may run in to other issues with spaces/special characters).
(You can re-enable wildcards afterwards with set +f)

How can I check dhcpd.conf against syntax error without running dhcpd?

I need to make sure there are no syntax errors on dhcpd.conf. If there are errors, I want to get what they are.
I can check for syntax errors with this command:
dhcpd -cf /path/to/dhcpd.conf
but that prints a lot of information in addition to the error I got. Another thing is that I don't want to run dhcpd, even there is no syntax error. I only want to check for syntax errors and see what they are.
Unfortunately, running dhcpd -tf /path/to/dhcpd.conf also didn't solve my problem.
The syntax you are looking for is
dhcpd -t -cf /path/to/dhcpd.conf
The -t option will do a config check:
If the -t flag is specified, the server will simply test the configuration file for correct syntax, but will not attempt to perform any network operations. This can be used to test the new configuration file automatically before installing it.
You do not need to use -cf if you are using the default config file path.
/usr/sbin/dhcpd -t
The one you tried with -tf /path/to/... is quite different and relates to tracing.
One thing not on the manual page, and not covered here yet, is that the '/usr/sbin/dhcpd -t' command uses the return value to indicate whether the configuration is correct or not.
If there are no errors, it will return zero. if there are syntax errors it will return non zero (1 for the test I did)
So you can use something like:
/usr/sbin/dhcpd -t
if [ $? -ne 0 ]; then
echo "Configuration has errors, aborting"
fi
/bin/systemctl restart isc-dhcp-server
To check if changes made to the configuration are valid before trying to restart the server with the new version.
Unfortunately I don't think there is any option to just display the errors. It would be possible to use a text parsing tool (awk, python etc) to remove the header lines (for the version I have, everything up to a line beginning with "For info"), and trailer lines (for the version I have, everything after a line saying "Configuration file errors encountered -- exiting") which would leave just the syntax error and location

Resources