question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to run commands with `/bin/bash -c` in v19.12.0

See original GitHub issue
Issue Type
  • Bug Report
Summary

GoCD v19.12.0

Steps to Reproduce

Run a job with the following command

              <exec command="/bin/bash">
                <arg>-c</arg>
                <arg>echo $HOME</arg>
                <runif status="passed" />
              </exec>
Expected Results

You should see the current path stored in the $HOME env var.

Actual Results
[go] Task: /bin/bash -ctook: 0.103sexited: 2
 "echo $HOME"
/bin/bash: -
: invalid option
Usage:	/bin/bash [GNU long option] [option] ...
	/bin/bash [GNU long option] [option] script-file ...
GNU long options:
	--debug
	--debugger
	--dump-po-strings
	--dump-strings
	--help
	--init-file
	--login
	--noediting
	--noprofile
	--norc
	--posix
	--rcfile
	--restricted
	--verbose
	--version
Shell options:
	-ilrsD or -c command or -O shopt_option		(invocation only)
	-abefhkmnptuvxBCHP or -o option
[go] Task status: failed, took: 0.103s, exited: 2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
kritika-singh3commented, Jan 8, 2020

@bsodmike I was able to reproduce the issue. As part of performance improvement to our pipeline config pages we started utilizing the Pipeline Config API to update tasks as part of https://github.com/gocd/gocd/pull/7400 . While updating the config, the task contains a \r in the args which is treated as a newline by the command line. So the config which is saved is

<exec command="/bin/bash">
                <arg>-c\r</arg>
                <arg>echo $HOME</arg>
                <runif status="passed" />
 </exec>

Since \r is a non-printable character, it is not visible on any UI. The logs I asked was to confirm that the command is actually not utilizing the echo part. Hence, the actual command which ran was /bin/bash -c which is an incorrect. Hence the error.

Now, the fix you mentioned was not due to removing the said line. It was because the whole config was overwritten by the arg without \r in it. Thanks for reporting the issue. I will take a deeper look into it later in this week.

1reaction
maheshpcommented, Jan 15, 2020

The other workaround is to save the cruise_config.xml without making any changes.

  1. Go to https://<gocd_server_url>/go/admin/config_xml
  2. Click Edit and Save
Read more comments on GitHub >

github_iconTop Results From Across the Web

'\r': command not found - .bashrc / .bash_profile - Stack Overflow
Try running the dos2unix command on the file in question. It might help when you see error messages like this: -bash: '\r': command...
Read more >
Cygwin error - Failed to run '/bin/bash': No such file or directory
I solved it by going to "C:\cygwin64\bin" and duplicating "ash.exe" and renaming the copy to "bash.exe". (I was trying this by pure chance,...
Read more >
Running bash scripts | Cloud Build Documentation
In the example below, the bash entrypoint is used to run gcloud commands that query Cloud Build for build status, listing builds with...
Read more >
command not found" errors running Bash scripts in WSL?
The easiest way to fix the problem is really to just download the files you need inside the Ubuntu system from your bash...
Read more >
Shell search PATH – finding and running commands
1 Shells find and run commands; 2 Identifying the command name ... 1 root root 59984 Nov 19 17:25 /bin/date $ /bin/date Sat...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found