4 ms·
My favorite discovery is how to efficiently do RPC style calls in BASH. Let's say you have some functions and variables you want to execute on a remote server.
by derekp7 13y ago
My favorite discovery is how to efficiently do RPC style calls in BASH. Let's say you have some functions and variables you want to execute on a remote server. Just do the following:
ssh remotehost "
$(declare -p var1 var2 var3)
$(declare -f func1 func2 remotemain)
remotemain"
In this example, var1, var2, var3 and func1, func2 are support variables/functions for the function "remotemain". This pushes all those to the remote side, then calls remotemain.
- e40 13y agoWow, that is very cool. The ways in which bash is used never cease to amaze me.
- dmytrish 13y agoAnd don't forget that you can still set the remote environment variables, use stderr output of the remote command, pipe it and so on: $ ssh remotehost "arecord | gzip -c" | gunzip -c | aplay records raw pcm stream an a remote machine, gzip's it and gunzip's and plays on the local machine.