cmd.run on command line with command substitution subshell

453 views
Skip to first unread message

Deyan

unread,
Sep 30, 2021, 2:16:05 PM9/30/21
to Salt-users

I would like to execute command substitution subshell on the minion from Salt Master command line.

For example, I would need to run something like this on the master...

salt '*' cmd.run 'for STR in `subshell command`; do something with $STR here; done'

Of course, it is not possible this way since subshell would be executed on master, and I need entire command and subshell to be executed on the minions.

Is it possible to somehow achieve this with cmd.run?

Thanks.

ende...@gmail.com

unread,
Oct 2, 2021, 4:43:45 PM10/2/21
to Salt-users
You should be able to escape the special characters.  I always recommend $() over tics (but it should work with tics too.  

salt \* cmd.run "for STR in \$(hostname); do echo \$STR; done"

Phipps, Thomas

unread,
Oct 2, 2021, 5:29:18 PM10/2/21
to salt-...@googlegroups.com

for what it is worth, you can also use ` within ‘ quotes without it being rendered on the command line

so

salt \* cmd.run 'for STR in `hostname`; do echo $STR; done'

Should work without issue.


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/1174a5d9-da7e-456d-9d68-fdef9410aa94n%40googlegroups.com.

Deyan

unread,
Oct 4, 2021, 4:11:22 AM10/4/21
to Salt-users
I did try both methods before, but I obviously made some mistake, and could not get it to work. It was a very long and complex command line, so I probably missed something.

I can confirm that both methods work properly. :)

Thank you.
Reply all
Reply to author
Forward
0 new messages