我正在尝试使用PSSH编写一个bash脚本,它发送相同的命令,但根据主机的不同而有不同的参数。主机名和参数将从不同的文件'list.txt‘中提取。
'list.txt‘文件的示例如下所示:
10.0.0.1;'hello';'world'
10.0.0.2;'goodbye';'everyone'
10.0.0.3;'thank';'you!'下面是我目前拥有的一个示例(但不幸的是不起作用):
#!/bin/bash
# grab the list items and make them into a variable to be able to parse
actionList=$(</root/scripts/list.txt)
# parse out host name for pssh
host_name="$( cut -d ';' -sf 1 <<< "$actionList" )";
# parse out the first argument
argument1="$( cut -d ';' -sf 2 <<< "$actionList" )";
# parse out the second argument
argument2="$( cut -d ';' -sf 3 <<< "$actionList" )";
# pssh command that creates a new file on each server with their respective argument1 and argument2
pssh -i -AH $host_name -t 300 -O StrictHostKeyChecking=no "$(argument1) ' and ' $(argument2) >> arg1_and_arg2.txt" 我非常确定删除pssh变量并不能得到我想要的结果,但我真正被困在的是,在我从$actionList中解析出正确的字符串后,$actionList命令是否对'list.txt‘中的每一项都能正确运行。
有没有一种方法可以让相同的命令,改变来自文件的参数与PSSH一起工作?有没有更好的程序来做这件事?如果是这样的话,是怎么做的?任何帮助都是非常感谢的。
谢谢!
附言:如果我在这篇文章中格式化或做错了什么,我向你道歉。StackOverflow通常是我最后的选择,所以我不经常使用它。再次感谢您的帮助/建议!
发布于 2019-02-06 02:54:22
我认为更好的做法是使用一个循环,为输入文件的每一行运行ssh。
while IFS=";" read host arg1 arg2; do
echo "$arg1 and $arg2" | ssh "$host" "cat > arg1_and_arg2.txt" &
done < list.txthttps://stackoverflow.com/questions/54539800
复制相似问题