linux - 如何在远程主机上运行 bash function()?在Ubuntu中

标签 linux bash shell ssh

<分区>

我正在运行一个 bash 脚本,但是当我尝试在远程机器上运行函数时,它说

bash: keyConfig: command not found

这是我的脚本:

keyConfig() {
    sed -i.bak -r "/^$1/s/([^']+')([^']+)('.*)/\1$2\3/" $3
}

remoteExecution() {
    ssh ppuser@10.101.5.91 " keyConfig $1 $2 $4 "
}

remoteExecution

最佳答案

简单的解决方法:

remoteExecution() {
    ssh ppuser@10.101.5.91 "`declare -f keyConfig`; keyConfig $1 $2 $4"
}

这里,keyConfig 只调用远程系统上可用的sed 命令。如果 keyConfig 已经调用了任何本地函数,那么也在 declare -f 的命令行中添加该函数。

这样,本地 shell 中的函数 keyConfig 在通过 ssh 生成的远程 shell 中定义,然后被调用。

关于linux - 如何在远程主机上运行 bash function()?在Ubuntu中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264657/

相关文章:

bash - 管道未在文件的读取命令中解释

Git Checkout 与 git bash 一起无限期挂起。怎么解决?

linux - 使用 curl 的 bash 脚本在 apache solr 中索引数据

c - 写入 Linux 设备驱动程序导致死循环

linux - 如何启动gitlab?

bash - 如何使用 SLURM 处理文件列表

php - echo 在 8 字节输入上写入成功,但在其他输入上写入失败

bash - 如何在 bash shell 中给出变量路径?

linux - 无法将参数从 shell 脚本传递到 Perl 脚本

linux - insmod 模块中的未知符号