首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想使用并行ssh在多个服务器上运行bash脚本,但是它简单地打印出echo语句。

我想使用并行ssh在多个服务器上运行bash脚本,但是它简单地打印出echo语句。
EN

Stack Overflow用户
提问于 2014-12-31 08:45:08
回答 1查看 9.7K关注 0票数 2

我有一个名为sr_run_batch.sh的bash脚本,它可以对图像进行超分辨率处理。现在,我想同时在不同的服务器上并行进行测试。即。1虚拟机在给定的时间点。然后,两个虚拟机在一个时间点,3,然后4。

代码语言:javascript
复制
for host in $(cat hosts.txt); do ssh "$host" "$command" >"output.$host"; done 
ssh-keygen && for host in $(cat hosts.txt); do ssh-copy-id $host; done

文件hosts.txt包含服务器列表:username@ip(格式),但当我运行此文件时,它会给出替换错误

因此,我尝试了pssh (并行-ssh)。

代码语言:javascript
复制
pssh -h hosts-file -l username -P $command

命令为./sr_run_batch.sh

但是它没有运行,所以我把它修改为

代码语言:javascript
复制
pssh -h hosts-file -l ben -P -I<./sr_run_batch.sh

但是,由于一些未知的原因,它只是在代码中打印echo语句。以下是代码:

代码语言:javascript
复制
NList=(5)    
VList=(1)    
FList=("input/flower1.jpg" "input/flower2.jpg" "input/flower3.jpg" "input/flower4.jpg")    
IList=("320X240"            "640X480"           "1280X960"          "1920X1200")    
SList=(2 3)    
for VM in ${VList[@]}; do

    for ((index=0; index < ${#FList};)) do
        file=$FList[$index]
        image_size=$IList[$index]
        width=`echo $image_size|cut -d "X" -f1`
        height=`echo $image_size|cut -d "X" -f2`
        for scale_factor in ${SList[@]}; do
            for users in ${NList[@]}; do 
                echo "V: $VM, " "F: $file, " "S: $scale_factor, " "I: $width $height , " "N: $users"
                for i in `seq 1 $users` ; do
                    ./sr_run_once.sh $file $width $height $scale_factor &
                done
                wait
            done # for users            
        done # for scale_factor
    done # for index
done # for VM
exit 0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-31 10:08:50

您是否也尝试过在一个简单的bash脚本中使用pssh,那么看看通信设置是否正常?

代码语言:javascript
复制
$ pssh -h hosts.txt -A -l ben -P -I<./uptime.sh
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password: 
10.0.0.67:  11:06:50 up 28 min,  2 users,  load average: 0.00, 0.00, 0.00
[1] 11:06:50 [SUCCESS] 10.0.0.67
10.0.0.218:  11:06:50 up 24 min,  2 users,  load average: 0.00, 0.05, 0.20
[2] 11:06:50 [SUCCESS] 10.0.0.218
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27718501

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档