condor: unmatched quotes when submitting bash jobs - bash

I wrote a conder script for a job and use condor_submit to submit this job. Below is my script:
Executable=/bin/bash
Arguments=" -c "" command_to_run -d -f"" "
initialdir= /path/
output=/path/out
error=/path/err
log=/path/log
universe = vanilla
Getenv = true
Queue
As seen above, the executable is bash and I use -c to pass the command as a string to bash. The job gets submitted fine, but I get the following error message in err output file:
command_to_run: -c: line 0: unexpected EOF while looking for matching `"'
command_to_run: -c: line 1: syntax error: unexpected end of file
This is simply bash complaining about unmatched double quotes. But double quotes look fine to me. I don't know what the problem is. It seems like it is a condor problem. Any ideas?

If you're just passing -c to bash then single quoting should be sufficient (unless you're trying to embed variables):
Arguments=" -c 'command_to_run -d -f' "

Related

Single quotes escaping Ruby

So, Im working with a Ruby script that needs to connect to a bunch of servers and get information from them. The problem I am having is that the single quotes seem to be getting lost somehow. What am I doing wrong here ?
command = "grep -E \'^(upstream| *server)\' /etc/nginx/upstreams.conf | sed -E \'s/_pool.*//g ; s/^upstream //g\'"
puts system("ssh -n -o 'StrictHostKeyChecking no' #{nginx_stage_servers[0]} #{command}")
Error I am getting :
$ ruby nx.rb
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `grep -E ^(upstream| *server) /etc/nginx/upstreams.conf'
true
The reason of the error is the single quotes missing.
You have too many layers of quoting and escaping to deal with when you use system(command_string), you're almost always better off using the multi-argument form of Kernel#system to avoid dealing with the shell. Something like this will be less problematic:
system('ssh', '-n', '-o', 'StrictHostKeyChecking no', nginx_stage_servers[0], command)

ruby - construct escaped command in code

I have the following command I execute via the windows 10 command prompt which works
C:>someapp.exe -n "conf:conf_abc:\"Acc 0 (ABC=234)\",\"ABC-DEF.GH.IJKL\",\"0\",\"\",\"0\",\"\"" -b input_file.abc -P vxyz > output_temp.def
I want to use this in Ruby code as a string command and execute it via system(command).
I do the following
command = "someapp.exe -n "conf:conf_abc:\"Acc 0 (ABC=234)\",\"ABC-DEF.GH.IJKL\",\"0\",\"\",\"0\",\"\"" -b input_file.abc -P vxyz > output_temp.def"
system(command)
This gives me error syntax error, unexpected tIDENTIFIER, expecting end-of-input
How do I go about formatting the command that works in command prompt to work within Ruby ?
Use %q sigil to prevent a string interpolation:
command = %q|someapp.exe -n "conf:conf_abc:\"Acc...|
system(command)

Makefile - Syntax error with for-loop

In a Makefile, I need to cycle through a list and write the current element of the list in a file.
The code is the following:
SHELL := /bin/bash
LIST = A B C
test:
for i in $(LIST) do \
echo $ii > file.txt \
done
I get the following error:
/bin/bash: -c: line 1: syntax error near unexpected token `>'
Do you know how to fix it?
You are missing a ; after $(LIST). You need to terminate the list of words you are giving to for before you can start the do block.
As indicated in the comments, you additionally need a : at the end of the echo line (the command that gets run has no newlines the way this works at the normal command line so you need to explicitly separate the commands from each other).
And further, to get the results you expect, you need to escape the $ in the shell command by using $$i (also pick one of $i or $ii as your variable name).

Executing a shell script with code accepted using I/O indirection

I am trying to execute a script like this, accepting script using indirection
sh <<EOT
for str in `cat test`
do
echo $str
done
EOT
The file "test" has contents
a
b
c
It gives below error.
sh: line 2: syntax error near unexpected token `b'
sh: line 2: `b'
Can anyone clarify ?. My aim is to execute the script like above instead of creating a shell script file script.sh and executing it (which works fine)
Your outer shell is interpolating the HEREDOC. To prevent that, quote the delimiter:
sh << 'EOT'
To clarify, what you have is equivalent to:
sh <<EOT
for str in a
b
c
do
echo
done
EOT
which makes the syntax error fairly obvious.

Shell script - check the syntax

How to check the correctness of the syntax contained in the ksh shell script without executing it? To make my point clear: in perl we can execute the command:
perl -c test_script.pl
to check the syntax. Is something similar to this available in ksh?
ksh -n
Most of the Borne Shell family accepts -n. tcsh as well.
I did a small test with the following code:
#!/bin/bash
if [ -f "buggyScript.sh" ; then
echo "found this buggy script"
fi
Note the missing ] in the if. Now I entered
bash -n buggyScript.sh
and the missing ] was not detected.
The second test script looked like this:
#!/bin/bash
if [ -f "buggyScript.sh" ]; then
echo "found this buggy script"
Note the missing fi at at end of the if. Testing this with
bash -n buggyScript.sh
returned
buggyScript.sh: line 5: syntax error: unexpected end of file
Conclusion:
Testing the script with the n option detects some errors, but by no means all of them. So I guess you really find all error only while executing the script.
The tests that you say failed to detect syntax errors, where not in fact syntax errors...
echo is a command (OK a builtin, but still a command) so ksh/bash are not going to check the spelling/syntax of your command.
Similarly "[" is effectively an alias for the test command, and the command expects the closing brace "]" as part of its syntax, not ksh/bash's.
So -n does what it says on the tin, you just haven't read the tin correctly! :-)

Resources