Executing a local shell function on a remote host over ssh using Python
<p>My <code>.profile</code> defines a function</p>

<pre><code>myps () {
        ps -aef|egrep "a|b"|egrep -v "c\-"
}
</code></pre>

<p>I'd like to execute it from my python script</p>

<pre><code>import subprocess
subprocess.call("ssh user@box \"$(typeset -f); myps\"", shell=True)
</code></pre>

<p>Getting an error back</p>

<pre><code>bash: -c: line 0: syntax error near unexpected token `;'
bash: -c: line 0: `; myps'
</code></pre>

<p>Escaping ; results in </p>

<pre><code>bash: ;: command not found
</code></pre>