I am trying to run a task in the background on a remote computer and get its PID code so that it can be killed later. So far I have come to the following:
#!/bin/bash
IP=xxx.xxx.xxx.xx
REMOTE_EXEC="ssh $IP -l root"
PID=`$REMOTE_EXEC 'vmstat 1 1000 > vmstat.log & ; echo $!'`
ab -n 10 http://$IP/
$REMOTE_EXEC "kill $PID"
Unfortunately this will not work. I get
bash: syntax error near unexpected token `;'
but I don’t know what the correct syntax will be.
source
share