【问题标题】:bash run command based on a list of ip [duplicate]基于ip列表的bash运行命令[重复]
【发布时间】:2016-04-25 06:15:49
【问题描述】:

我创建了这个 bash 脚本来在我的ip_list 中列出的每个主机上运行 python 代码:

#!/bin/bash

declare -a ip_list=('10.99.1.1' '10.99.1.2' '10.99.1.3"' '10.99.1.4');

for i in $(ip_list) ; do 
    ssh -i ~/Downloads/abc.pem -t -t ec2-user@$i "sudo   python /home/user/abc.py"
done

但我得到了错误:

Error: line 4: ip_list: command not found

我在这里做错了什么?谢谢

【问题讨论】:

  • 使用:for i in "${ip_list[@]}" ; do$(ip_list) 尝试运行ip_list 命令

标签: linux bash shell


【解决方案1】:

按照@anubhava 的建议,试试 ${ip_list[@]},如下所示:

declare -a ip_list=('10.99.1.1' '10.99.1.2' '10.99.1.3' '10.99.1.4');

for i in ${ip_list[@]} ; do
    ssh -i ~/Downloads/abc.pem -t -t ec2-user@$i "sudo   python /home/user/abc.py"
done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多