Run if statement on remote machine

view story

http://unix.stackexchange.com – I'm trying to run a set of commands on a remote machine, that includes an if statement. I'm using this to shutdown a list of kvm instances. The first line should be fine, but could be prettier, rest needs some help. ssh root@kvmsrv 'virsh shutdown $host 2> /dev/null; virsh destroy $host 2> /dev/null; sleep 2; virsh undefine $host 2> /dev/null' # Also needs to be run on remote machine # to disconnect iscsi iscsiadm -m session | grep $host if [ $? == 0 ]; then iscsiadm -m node -T $stserver.$host -u fi # then on local machine tid=`ssh root@storage1 'cat /proc/net/iet/volume' | grep (HowTos)