LINUX - saltstack cmd.run 中的一个变量
LINUX - saltstack cmd.run in a variable
我知道我可以使用 sls 从 salt 执行 运行 命令,但我需要通过 bash 脚本 运行 某些命令。我需要将命令的结果存储到一个变量中。
当 运行在 salt 服务器的 shell 上执行以下操作时,我得到了一个结果
salt -t70 'server' cmd.run "cat /etc/shadow | grep user |cut -d: -f3"
但是当我将命令迁移到盐服务器中 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");
我知道我可以使用 sls 从 salt 执行 运行 命令,但我需要通过 bash 脚本 运行 某些命令。我需要将命令的结果存储到一个变量中。
当 运行在 salt 服务器的 shell 上执行以下操作时,我得到了一个结果
salt -t70 'server' cmd.run "cat /etc/shadow | grep user |cut -d: -f3"
但是当我将命令迁移到盐服务器中 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");