Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Arguments break shell command on Mac #80

Open
ihortom opened this issue Oct 20, 2016 · 9 comments
Open

Arguments break shell command on Mac #80

ihortom opened this issue Oct 20, 2016 · 9 comments

Comments

@ihortom
Copy link

ihortom commented Oct 20, 2016

Running on Mac doesn't seem to work if options for the script are specified in "arguments". I had to put the whole command into one line in "command" property to make it work.

When run, the output suggests inappropriate use of the command. Having the option --dry-run added produces the command like below (with paths removed for brevity)

"sh" "-c" "ssl_cert_check.sh \"-f\" \"ssldomain.txt\" \"-x\" \"60\""

In comparison, when the whole command is used in "command" property, the dry run produces

"sh" "-c" "ssl_cert_check.sh -f ssldomains.txt -x 60 "

I guess it might be something to do with the quotes.

@ninjabear
Copy link
Contributor

ninjabear commented Oct 20, 2016

I have tried to repeat this using the following cut down job:

https://github.com/snowplow/factotum/tree/osx-args-tree/int-test

The results are identical on Linux/OSX:

Linux: https://travis-ci.org/snowplow/factotum/jobs/168386920#L212-L216
macOS: https://travis-ci.org/snowplow/factotum/jobs/168386921#L114-L118

What's different? What shell/version are you using?

Edit: I know both builds list as "failed" but that's because I haven't set up the return codes properly, they haven't actually "failed"

@ihortom
Copy link
Author

ihortom commented Oct 20, 2016

$ bash --version
bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.

Wonder why bash --version is being duplicated in the output.

@alexanderdean
Copy link
Contributor

I am pretty sure I've seen this in the wild too... Sorry I know that's very vague, but there's definitely something rare and intermittent in Factotum's handling of CLI args to tasks...

@ninjabear
Copy link
Contributor

I have created these scripts:

#!/usr/bin/env ruby

puts ARGV.inspect
#!/usr/bin/python

import sys

print str(sys.argv)

and tried them both with this command:

"sh" "-c" "ssl_cert_check.sh \"-f\" \"ssldomain.txt\" \"-x\" \"60\""

both print the expected for me, using any shells I could find on my system:

either:
["-f", "ssldomain.txt", "-x", "60"]

or:
['./ssl_cert_check_py.sh', '-f', 'ssldomain.txt', '-x', '60']

which is as I expect

@ninjabear
Copy link
Contributor

What's the exact error message @ihortom ? Can you paste it here please? There must be something I've missed

@ihortom
Copy link
Author

ihortom commented Oct 20, 2016

$ ~/factotum run main-prod.factfile
~/factotum run main-prod.factfile
Task 'ssl_cert_check' was started at 2016-10-20 21:55:43.778947 UTC
Task 'ssl_cert_check' stdout:
Usage: /Users/ihor/github/snowplow/snowplow-devops/support-tools/ssl_cert_check/ssl_cert_check.sh [ -e email address ] [ -x days ] [-q] [-a] [-b] [-h] [-i] [-n] [-v]
       { [ -s common_name ] && [ -p port] } || { [ -f cert_file ] } || { [ -c certificate file ] }

  -a                : Send a warning message through E-mail
  -b                : Will not print header
  -c cert file      : Print the expiration date for the PEM or PKCS12 formatted certificate in cert file
  -e E-mail address : E-mail address to send expiration notices
  -f cert file      : File with a list of FQDNs and ports
  -h                : Print this screen
  -i                : Print the issuer of the certificate
  -k password       : PKCS12 file password
  -n                : Run as a Nagios plugin
  -p port           : Port to connect to (interactive mode)
  -s commmon name   : Server to connect to (interactive mode)
  -t type           : Specify the certificate type
  -q                : Don't print anything on the console
  -v                : Specify a specific protocol version to use (tls, ssl2, ssl3)
  -V                : Only print validation data
  -x days           : Certificate expiration interval (eg. if cert_date < days)
Task 'ssl_cert_check': failed after 0.0s. Reason: the task exited with a value not specified in continue_job - 1 (task expects one of the following return codes to continue [0])
1/1 tasks run in 0.0s
Factotum job executed abnormally as a task ('ssl_cert_check') failed - the following tasks were not run: !
echo -ne "\033]0;${PWD##*/}\007"

@ninjabear
Copy link
Contributor

Can you post the output of just the arguments the process is receiving? It's a bit hard to work out from that what's occurring - this python script will do the trick:

#!/usr/bin/python

import sys

print str(sys.argv)

@ihortom
Copy link
Author

ihortom commented Oct 20, 2016

$ "sh" "-c" "./test.py \"-f\" \"ssldomain.txt\" \"-x\" \"60\""
"sh" "-c" "./test.py \"-f\" \"ssldomain.txt\" \"-x\" \"60\""
['./test.py', '-f', 'ssldomain.txt', '-x', '60']
echo -ne "\033]0;${PWD##*/}\007"

@ninjabear
Copy link
Contributor

as discussed this is as expected, no clues as to why this doesn't work yet

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants