如何在远程主机上运行bash function()?在Ubuntu中 [英] How to run a bash function() in a remote host? in Ubuntu

查看:45
本文介绍了如何在远程主机上运行bash function()?在Ubuntu中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 bash 脚本,但是当我尝试在远程计算机上运行功能时,它会说

I am running a bash script, but when I try to run functions on a remote machine, it says

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

推荐答案

请重试该错误:

完成时

ssh ppuser@10.101.5.91 " keyConfig $1 $2 $4 "

您实际上是在尝试在远程计算机 10.101.5.91 上执行命令 keyConfig 肯定不存在:

You are actually trying to execute a command keyConfig on remote machine 10.101.5.91 Which is certainly not there:

2解决问题的方法

1)在remotehost上创建一个脚本,该脚本包含具有相同名称的 keyConfig 代码

1) Make a script on remotehost which contains keyConfig code with same name

OR

2)执行以下命令,而不是执行功能

2) Execute following instead of function

ssh ppuser@10.101.5.91 "sed -i.bak -r "/^$1/s/([^']+')([^']+)('.*)/\1$2\3/" $3"

请注意,根据您使用的sed语法,您可能必须添加一些转义符

这篇关于如何在远程主机上运行bash function()?在Ubuntu中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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