Skip to main content
SaltStack Support

How can I run a Bash script from the master on a minion?

Use cmd.script to download a script from a remote location and execute the script locally. The script can be located on the salt master file server or on an HTTP/FTP

The script will be executed directly, so it can be written in any available programming language.

The script can also be formated as a template -- the default is Jinja. Arguments for the script can be specified as well.

CLI Example:

salt '*' cmd.script salt://scripts/
salt '*' cmd.script salt://scripts/ 'arg1 arg2 "arg 3"'
salt '*' cmd.script salt://scripts/ saltenv=dev
salt '*' cmd.script salt://scripts/windows_task.ps1 args=' -Input c:\tmp\infile.txt' shell='powershell'

A string of standard input can be specified for the command to be run using the ``stdin`` parameter. This can be useful in cases where sensitive
information must be read from standard input.:

salt '*' cmd.script salt://scripts/ stdin='one\ntwo\nthree\nfour\nfive\n'
cmd.script(source, args=None, cwd=None, stdin=None, runas=None, shell='/bin/sh', python_shell=True, env=None, 
template='jinja', umask=None, output_loglevel='debug', quiet=False, timeout=None, reset_system_locale=True, __env__=None, 
saltenv='base', use_vt=False, **kwargs)

  • Was this article helpful?