For this purpose I wrote a small shell script which I execute on the remote side:
#!/bin/bash
# check for command line arguments
if [ $# -lt 2 ]; then
echo "usage: runcommand.sh EXECUTIONSTRING TASKNAME"
exit -1
fi
taskname=$2
execstr=$1
logfile=$taskname.log
echo START $taskname > $logfile
echo OWNPID $BASHPID >> $logfile
stime=`date -u +"%Y-%m-%d_%H-%M-%S"`
stimes=`date -u +"%s"`
echo STARTTIME $stime >> $logfile
echo STARTTIMES $stimes >> $logfile
# execute program
$execstr 1>$taskname.stdout 2>$taskname.stderr
echo RETVAL $? >> $logfile
stime=`date -u +"%Y-%m-%d_%H-%m-%S"`
stimes=`date -u +"%s"`
echo STOPTIME $stime >> $logfile
echo STOPTIMES $stimes >> $logfile
echo STOP $taskname >> $logfile
What it does: executes a given task, pipes the output of stdout, stderr to two different files and creates a logfile which saves when the task was started, when it finished and the return value of the task.
Then I first copy the script to the remote host and execute it there with exec_command:
command = './runcommand.sh "{execpath}" "{taskname}" > /dev/null 2>&1 &'
ssh.exec_command(command.format(execpath=anexecpath, taskname=ataskname)