This question already has an answer here:
I am running a bash
script, but when I try to run functions on a remote machine, it says
bash: keyConfig: command not found
Here is my script:
keyConfig() {
sed -i.bak -r "/^$1/s/([^']+')([^']+)('.*)/\1$2\3/" $3
}
remoteExecution() {
ssh ppuser@10.101.5.91 " keyConfig $1 $2 $4 "
}
remoteExecution
Simple work-around:
Here,
keyConfig
only callssed
command, which is available on remote system. IfkeyConfig
had been calling any local function, then add that function also indeclare -f
's command line.This way, the function
keyConfig
in the local shell gets defined in the remote shell spawned via ssh & then it gets called.keyConfig
is not define as a command in the host "10.101.5.91"You could try to define a bash script which is called
keyConfig
in the host "10.101.5.91" and add that script in theppuser
PATH.Resone for the error:
When you do
You are actually trying to execute a command
keyConfig
on remote machine10.101.5.91
Which is certainly not there:2 Solution for the problem
1) Make a script on remotehost which contains
keyConfig
code with same nameOR
2) Execute following instead of function
Please note you may have to add few escape depending on the sed syntax you are using