【问题标题】:passing a function as parameter to a remote server via ssh command通过 ssh 命令将函数作为参数传递给远程服务器
【发布时间】:2014-06-18 14:34:39
【问题描述】:

我想知道是否可以将整个函数作为参数传递给远程服务器以在远程服务器上执行一长串操作并将控制流返回给本地服务器。

在 shell/bash 脚本中。

例如:

如下所示:

test_abc() {  
    # this function perform a long list of commands to be performed on remote server  
    command 1;   
    command 2;  
    .  
    ..  
    command N;  

    few echo commands;    
}  

ssh user@remote_server test_abc;    

我不确定这在 shell 脚本中是否可行。请告诉我。

【问题讨论】:

    标签: linux bash shell unix ssh


    【解决方案1】:

    显然,远程系统无法理解本地环境中的任何内容。 “test_abc”必须是“remote_server”上已知的命令。

    ssh user@remote_server "$(cat <<- _EOF_
    ((command-list))
    _EOF_
    )"
    

    那个,或者引用“test_abc”的主体,但它可能需要摆弄才能正确引用。

    【讨论】:

    • 得到错误,伪终端将不会被分配,因为stdin不是终端。
    • ssh user@server "$( cat
    猜你喜欢
    • 2017-05-18
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多