salt icon indicating copy to clipboard operation
salt copied to clipboard

salt cmd.run arg parsing using --

Open joshmule opened this issue 11 years ago • 11 comments

It would be nice to execute cmd.run with commands and command args not needing double quotes. I'd like to see something like this:

salt minionname cmd.run -- tail /path/file

... without seeing:

ERROR: Specified cwd '/path/file' either not absolute or does not exist

Thoughts?

joshmule avatar Apr 30 '15 19:04 joshmule

This gets tricky with the shell helping out/getting in the way and how we process command line arguments to modules, but if you would rather prepend a -- than quote, then I think it could be implemented. @basepi or @cachedout may have better opinions on this subject.

Note also that arguments can be single quoted as well as double quoted. Standard shell considerations apply when deciding which.

jfindlay avatar May 01 '15 01:05 jfindlay

The -- will prevent the argument parser from looking for any further - arguments, but it will not otherwise modify the remaining arguments, which we will still receive split on spaces, and then interpret as separate arguments to the salt command in question. You have to use quotes to group them into a single argument.

salt minionname cmd.run -- 'tail /path/file'

results in cmd.run('tail /path/file') while

salt minionname cmd.run -- tail /path/file

results in cmd.run('tail', '/path/file'). I don't think this is something we want to change, as it's a backwards-incompatible change, and gains us very little. (Maybe a couple of keystrokes? But no, because you have to type the --, so it saves nothing...)

basepi avatar May 01 '15 20:05 basepi

Closing this for now, but we'll still monitor for replies if you want to discuss further.

basepi avatar May 01 '15 20:05 basepi

I guess I'm just coming from the -- standard for most gnu tools and others. "--" is almost universal for "and everything after this is the rest of the command". Something I just used was: watch -d -- free -m

I wanted to take that forward in salt if it didn't break anything, but I understand if it does.

On Fri, May 1, 2015 at 4:40 PM, Colton Myers [email protected] wrote:

Closing this for now, but we'll still monitor for replies if you want to discuss further.

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/23232#issuecomment-98230841.

Joshua Jensen

joshmule avatar May 01 '15 22:05 joshmule

Right, and the same works in salt. But the issue is that we process "the rest of the command" as space-separated args, so we still need the quotes, unfortunately.

basepi avatar May 01 '15 22:05 basepi

Are space-separated args part of the history of the salt command? Do people do multiple commands this way, or do they just find that they forgot to add the quotes?

In theory the presence of a -- could explicitly signify "the rest of the line is one command and its args", though that twist might not be inline with the history of the salt command, and would just confuse users

On Fri, May 1, 2015 at 6:20 PM, Colton Myers [email protected] wrote:

Right, and the same works in salt. But the issue is that we process "the rest of the command" as space-separated args, so we still need the quotes, unfortunately.

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/23232#issuecomment-98253632.

Joshua Jensen

joshmule avatar May 01 '15 22:05 joshmule

Not multiple commands. Multiple arguments to a single salt remote execution module function.

salt <target> <module.function> [arg1] [arg2] [arg3]

basepi avatar May 04 '15 19:05 basepi

Hi

i am not able to do a continuous tail from salt master

the command that i use is

salt -S 10.x.x.x cmd.run 'tail -f /var/log/nginx'

Lokeshs2290 avatar Jun 03 '15 14:06 Lokeshs2290

@Lokeshs2290 This is because salt does not keep a streaming connection open to the command in question, it only returns the output when the command ends. So streaming commands like tail -f will not work with cmd.run.

basepi avatar Jun 03 '15 16:06 basepi

@basepi Thanks for the quick reply

is there any way i can stream log files from saltstack master .???

Lokeshs2290 avatar Jun 03 '15 18:06 Lokeshs2290

@Lokeshs2290 not currently, no. I think we could construct such a feature using salt-vt, but it will take a little work. Would you mind opening a new issue with this feature request?

basepi avatar Jun 04 '15 16:06 basepi