1

リモートホストAの.bashrcファイルを介して供給される関数があります。リモートホストAで「which」を使用すると、関数本体が出力として取得されます。別のホストBからリモートでsshを介して実行する必要があります。現在、すべての試行は「コマンドが見つかりませんエラー」で終了しています。私はすでにに渡そうとしました

ssh A  "source /home/user/.bashrc && function "  

、これは役に立ちません。また、sshに-tキーを使用してpseudo-ttyを強制的に送信させてみました。両方のホストのSHELLはbashです。ホストAのsshlocalhostは、引き続き機能ステータスを使用可能にします。

出力:

[user@hostA ~]$ which status
status is a function
status ()
{
    dos -s $*
}


[user@hostB ~]$ ssh hostA " source  /home/user/deploy/bin/_bashrc && status all "
ls: : No such file or directory
bash: status: command not found
4

2 に答える 2

1

Basically, you can't. To do that you need to copy the sourced file on the remote host and source it in there. Note, that your file may be sourcing in some other files as well… This is almost like running local program on the remote host.

于 2012-09-12T16:42:02.230 に答える
0

The trick is to get the remote end to properly load your file containing the function into the shell environment.

I found with bash that the following works... Put your function into .bashrc on the remote:

foo_func()
{
    echo Hello World
}

Then on the local side:

ssh user@remote bash -l -c foo_func

The bash -l instructs bash to run as a login shell (sourcing startup files) and then the -c tells the shell to execute the string foo_func.

于 2014-04-23T16:59:47.000 に答える