shell script for multiple logging

Hi All,

I am preparing a script which executes following things:

1) Logs into 8 cluster one by one.
2) After logging into each cluster,it prints the cluster name & then exit from that cluster.
3) Then it logs to next cluster & peform the same task.

Here is what i have written :

for ((i =1;i<=8;i++))
do
ssh cluster$i
echo "cluster$i"
exit
done

Currently what is happening is it is logging into all the cluster simultaneously without printing the cluster number & exiting from that cluster.

Please help on what wrong i am doing here.

Thanks

see the options of ssh -t -n -x -X ...

man ssh
for ((i =1;i<=8;i++))
do
#
  ssh cluster$i echo
  result=$?
  if(result==0)
  then
    echo "success ssh cluster$i"
  else
    echo "fail ssh cluster$i"
  fi
#
  exit
done

Thanks all for your responses.
I am still not able to get the script works as expected.
I want to login into each of eight cluster & delete the directory work under /opt/space/.
This directory is available in each cluster at same location.

you can replace command echo by your specific command, eg. rm -rf /opt/space/*

 
for ((i =1;i<=8;i++))
do
ssh cluster$i "rm -rf /opt/space/*"
done

Hi All,

Here is the script which i am executing.It is deleting the content from first cluster only.Not in all 8.
Please let me know where i am wrong

for ((i =1;i<=8;i++))
do
#
  ssh cluster$i "rm -rf /tmp/abc"
  result=$?
  if(result==0)
  then
    echo "success"
  else
    echo "fail"
  fi
#
  exit
done


why u put exit ?

exit

remove the exit

Remove the "exit" that is in your "for" loop