如何正确转义使用ssh命令中长输入ARGS qsub命令? [英] How to properly escaping qsub command with long input args within ssh command?

查看:196
本文介绍了如何正确转义使用ssh命令中长输入ARGS qsub命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的qsub命令远程运行。

I have a complex qsub command to run remotely.

PROJECT_NAME_TEXT="TEST PROJECT"
PACK_ORGANIZATION="--source-organization \'MY, ORGANIZATION\'"
CONTACT_NAME="--contact-name \'Tom Riddle\'"
PROJECT_NAME_PACK="--project-name \"${PROJECT_NAME_TEXT}\""


INPUTARGS="${PACK_ORGANIZATION} ${CONTACT_NAME} ${PROJECT_NAME_PACK}"

ssh mycluster "qsub -v argv="$INPUTARGS" -l walltime=10:00:00 -l vmem=8GB -l nodes=1:ppn=4 /myscript_path/run.script" 

问题是远程集群不承认qsub命令,它总是显示不正确qsub命令或者干脆集群送花儿给人排队,因为输入参数数量是错误的。

The problem is the remote cluster doesn't recognise the qsub command, it always showing incorrect qsub command or simply alway queued on cluster because of input args are wrong.

它必须是逃避问题,我的问题是如何正确以上逃脱命令?

It must be the escaping problem, my question is how to escape the command above properly ?

推荐答案

感谢所有的答案,但是他们的方法会不会对我的情况下工作。我有我自己,因为这个问题是pretty复杂回答这个问题,我得到的线索,从计算器现有的解决方案。

Thanks for all the answers, however their methods will not work on my case. I have to answer this by myself since this problem is pretty complex, I got the clue from existing solutions in stackoverflow.

有两个问题必须在我的案件得到解决。

There are 2 problems must be solved in my case.


  1. 通过本地程序的参数到远程集群。这里-doc的解决方案并不能在这种情况下工作。

  1. Pass local program's parameters to the remote cluster. Here-doc solution doesn't work in this case.

与长变量包含引号符号参数远程集群上运行的qsub。

Run qsub on remote cluster with the a long variable as arguments that contain quote symbol.

问题1。

首先,我要介绍我的脚本,在本地机器上运行需要的参数是这样的:

Firstly, I have to introduce my script that runs on local machine takes parameters like this:

scripttoberunoncluster.py --source-organisation "My_organization_my_department" --project-name "MyProjectName"  --processes 4 /targetoutputfolder/

的真实参数大于上述更长得多,所以所有的参数必须被发送到遥控器。他们将在文件发送这样的:

The real parameter is far more longer than above, so all the parameter must be sent to remote. They are sent in file like this:

PROJECT_NAME="MyProjectName"
PACK_ORGANIZATION="--source-organization '\\\"My_organization_my_department\\\"'" # multiple layers of escaping, remove all the spaces
PROJECT_NAME_PACK="--project-name '\\\"${PROJECT_NAME}\\\"'"
PROCESSES_="--processes 4"
TARGET_FOLDER_PACK="/targetoutputfolder/"

INPUTARGS="${PACK_ORGANIZATION} ${PROJECT_NAME_PACK} ${PROCESSES} ${TARGET_FOLDER_PACK}"

echo $INPUTARGS > "TempPath/temp.par"
scp "TempPath/temp.par" "remotecluster:/remotepath/"

我的解决方案是那种妥协。但这种方式远程群集可以运行脚本参数包含引号的象征。如果你不把所有的变量(如参数)在一个文件并将其传输到远程集群,无论你如何将它们传递到变量,报价符号将被删除。

My solution is sort of compromising. But in this way the remote cluster can run script with arguments contain quote symbol. If you don't put all your variable (as parameters) in a file and transfer it to remote cluster, no matter how you pass them into variable, the quote symbol will be removed.

问题2。

检查的qsub远程群集上的运行方式。

Check how the qsub runs on remote cluster.

ssh remotecluster "qsub -v argv=\"`cat /remotepath/temp.par`\" -l walltime=10:00:00 /remotepath/my.script"

而在my.script:

And in the my.script:

INPUT_ARGS=`echo $argv`

python "/pythonprogramlocation/scripttoberunoncluster.py" $INPUT_ARGS ; #note: $INPUT_ARGS hasn't quote

这篇关于如何正确转义使用ssh命令中长输入ARGS qsub命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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