I'm running few commands on a remote server, by sshpass.

  gnome-terminal --maximize 
  --tab --title='aTask' -e "sshpass -p "afsd@#$5u89f"  ssh root@ 'command1 && command2'" \

So my question is, what if my last command is mvn clean install, then how may I know that the build was successful?

In a way I need to track down my first child process whether it has completed all the commands successfully, so that I can start another child process sequentially.


If you want to run sequentially then the exit code is all you need;

command && echo "it worked"


command || echo "we are having a bad day"

If gnome-terminal or sshpass is not returning the correct return code file a bug report and use an alternative.

If you want to run in parallel use xargs -P or parallel where the

exit status is the combination of the exit statuses of each command ran, ORed together. (Thus, if any one command exits nonzero, parallel as a whole will exit nonzero.)

If one of your commands is returning before execution use an alternative or make your commands adopt an asynchronous design pattern (re-invent the wheel) eg by appending

 ; echo $(date) $? > task1.r

then waiting for all tasks to complete;

while [ $(cat task*.r 2>/dev/null | wc -l) -lt $TASK_COUNT ] ; do
    sleep 1
grep -P " [^0]$" task*.r && echo "we are having a bad day"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.