我想使用parallel-ssh在多个服务器上运行bash脚本,但是它可以简单地打印echo语句 [英] I want to use parallel-ssh to run a bash script on multiple servers, but it simple prints the echo statements

查看:68
本文介绍了我想使用parallel-ssh在多个服务器上运行bash脚本,但是它可以简单地打印echo语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 sr_run_batch.sh 的bash脚本,它可以对图像进行超分辨率.现在,我想同时在不同的服务器上同时进行测试.IE.1个给定时间点的虚拟机.然后在一个时间点先配置2个虚拟机,再分别配置3个和4个虚拟机.我尝试将命令写入其中

I have a bash script called sr_run_batch.sh which does super resolution of images. Now I want to do testing on different servers in parallel at the same time. ie. 1 Virtual machine at one given point of time. then 2 virtual machines at one point of time , 3 and then 4. I tried writing into it the commands

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 (格式),但是当我运行它时,它给了我替换错误

where the file hosts.txt contains the list of servers: username@ip(format) but when I run this, it gives me substitution error

因此,我尝试了pssh(parallel-ssh)

Hence, I tried pssh (parallel-ssh)

pssh -h hosts-file -l username -P $command

命令为 ./sr_run_batch.sh

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

but it didn't run, so I modified this to

pssh -h hosts-file -l ben -P -I<./sr_run_batch.sh

但是,由于某些未知的原因,它只是在代码中打印echo语句.这是代码:

But, for some unknown reason, it just prints the echo statements in the code. here is the code :

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

推荐答案

您是否还尝试过将pssh与简单的bash脚本一起使用,以便查看通信是否正常?

Have you also tried to use pssh with a simple bash-script so see if the communication is set up ok?

$ 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

这篇关于我想使用parallel-ssh在多个服务器上运行bash脚本,但是它可以简单地打印echo语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆