LINUX - saltstack cmd.run 在变量中

标签 linux bash shell salt-stack

我知道我可以使用 sls 从 salt 运行命令,但我需要通过 bash 脚本运行某些命令。我需要将命令的结果存储到一个变量中。

当在 salt 服务器的 shell 上运行以下命令时,它可以工作并且我得到了一个结果

salt -t70 'server' cmd.run "cat /etc/shadow | grep user |cut -d: -f3"

但是当我将命令迁移到 salt 服务器中 bash 文件内的变量时,它不会。

BASH.SH

test = $(echo salt -t70 $server cmd.run "cat /etc/shadow | grep $user |cut -d\":\" -f3");
echo $test;

错误信息

[root@saltserver ~]# sh bash.sh
bash.sh: line 13: test: too many arguments

我错过了什么?我需要修复什么才能使其正常工作? 谢谢

最佳答案

您不能在赋值中将空格放在 = 周围——这样做会使操作……好吧,不再是赋值。也就是说:

使用

# assign result to a variable named test
test=$(echo salt -t70 $server cmd.run "cat /etc/shadow | grep $user |cut -d\":\" -f3");

不是

# run the command named test, with its first argument '=' and its second argument
# taken from the results of invoking saltstack.
test = $(echo salt -t70 $server cmd.run "cat /etc/shadow | grep $user |cut -d\":\" -f3");

关于LINUX - saltstack cmd.run 在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30360163/

相关文章:

python - 列表中的目录内容

python - edX LMS 端口 8000 已在使用中(即使在终止进程之后)

bash 分配默认值

linux - 查看路径的所有中间目录的权限?

oracle - libclntsh.so.11.1 : cannot open shared object file.

linux - 计算shell中文件的大小

php - 配置 SAPRFC + PHP5 失败

linux - 从 bash 脚本终止 ssh 或\和远程进程

performance - BASH:一次设置多个变量/性能

shell - 在构建任何目标后强制 Makefile 执行脚本(就在退出之前)