Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below, but its running both the commands on all the server's, which i dont want to.

#!/usr/bin/ksh
# set -x
ofile=/old_rootvg_cleanup_logs/old_rootvg-cleanup.$$
for server in `cat host_list.txt`
do
remove_old_rootvg=`ssh $server alt_rootvg_op -X old_rootvg`
if [ $? != 0 ]
then
echo "Command Failed at $server"
else 
export_old_rootvg=`ssh $server exportvg old_rootvg"
fi
echo " $server   |   $remove_old_rootvg  |    $export_old_rootvg" >> $ofile
done 

---------- Post updated at 06:56 PM ---------- Previous update was at 06:37 PM ----------

remove_old_rootvg=`ssh $server alt_rootvg_op -X old_rootvg`
echo $?

Does this always return 0 as status($?)?
If so, Is the remote script exiting with a 0 if successful(i.e. exit 0) and non zero if unsuccessful(i.e. exit 1)?

it returns exit 1 as when it deletes using command "alt_rootvg_op -X old_rootvg" will return exit 0.

Is the remote script exiting with a 0 if successful(i.e. exit 0) and non zero if unsuccessful(i.e. exit 1)? YES

Try it with the command in quotes, like this:

remove_old_rootvg=`ssh $server 'alt_rootvg_op -X old_rootvg'`

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below, but its running both the commands on all the server's, which i dont want to.

I did another test and this should work for what you want, notice the single quotes around the script and it's parameters being run on the remote server(s):

#!/usr/bin/ksh
# Script:  test.sh
for server in `cat host_list.txt`
do
  remove_old_rootvg=`ssh $server 'alt_rootvg_op -X old_rootvg'`
  rc="$?"
  echo $rc
  if [[ $rc = 1 ]] then
    echo "Command Failed at $server"
  else 
    export_old_rootvg=`ssh $server 'exportvg old_rootvg'`
    rc="$?"
    echo $rc
    if [[ $rc = 1 ]] then
      echo "exportvg Failed at $server"
    fi
  fi
done

Firstly in "lsvg | grep old" here if the output is "old_rootvg", script would then delete it by "alt_rootvg_op -X old_rootvg", and check again "lsvg | grep old" if no output then "old_rootvg" is deleted, if output is shown as "old_rootvg" existing, then script would "exportvg old_rootvg".