我知道我可以在SSH会话中调用本地shell中的变量,所以我认为我也可以用这种方式调用函数。但这似乎并不奏效。我可以从ssh调用本地函数吗?
我有一个脚本,检查我的本地计算机是否可以处理某些操作,以及是否需要调用本地函数,如果本地计算机无法通过SSH连接到远程计算机并调用本地函数。
canHandle() {
if [ -d /this_must_exist/ ]
then
return 0
else
return 1
fi
}
localFunction() {
// Predefined tasks
}
canHandle
if [ $? -eq 0 ]
then
// Process locally using predefined functions
localFunction
else
ssh -t [email protected] << ENDSSH
// Process remotely calling predefined local functions
localFunction
ENDSSH
fi
可能重复[Shell脚本:从脚本通过ssh运行函数](http://stackoverflow.com/questions/22107610/shell-script-run-function-from-script-over-ssh) – RASG