Script to iterate over several options

Have two 3 files which has list of servers,users and location and base url which is common on every server

A = server1 server2 server3
B = user1 user2 user3
C =  dom1 dom2 dom3
baseurl=/opt/SP/

and what i have to achieve is below via ssh from REMOTE SERVER

for it's first iteration it ssh to user1@server1 and goes to /opt/SP/user1/dom1
for it's second iteration it ssh to user2@server2 and goes to /opt/SP/user2/dom2
for it's third iteration it ssh to user3@server3 and goes to /opt/SP/user3/dom3

Please advise

Welcome to the forum.

Any attempts / ideas / thoughts from your side?

What does "two 3 files" mean when you show just one sample file?

Will there always be three possibilities for each or might the numbers vary? Can there be quoted strings like:

dom = dom1 "this is dom2" dom3

to take into account? Will the field separator always be a single space?

I hope this helps.

bakunin

BASE=/opt/SP/
set -- server1 user1 dom1 server2 user2 dom2 server3 user3 dom3

while [ "$#" -gt 0 ]
do
        ssh -t "$2@$1" "cd $BASE/$3 ; exec bash"
        shift 3
done

Thanks all for you swift response for you comments
As i was new to scripting , it helped ,solution suggested by Corona688 worked for me.

Thanks
Abhay

If I remember correctly, you "Have two 3 files which has list of servers,users and location and base url". How do you massage those data into the form Corona688's proposal requires?

It was 3 files , two was a typo

Although i am sure Corona688s suggestion is working fine for reasons of maintainability and understandability my suggestion is to use arrays for this kind of data. If the number of paramter sets to cycle through increases it is easier to extend this way. Something like this:

BASE=/opt/SP/
server[1]="server1" ;    user[1]="user1"  ;     dom[1]="dom1"
server[2]="server2" ;    user[2]="user2"  ;     dom[2]="dom2"
server[3]="server3" ;    user[3]="user3"  ;     dom[3]="dom3"

(( i = 1 ))
while [ $i -le ${#server[@]} ] ; do
        ssh -t "${user[$i]}@${server[$i]}" "cd $BASE/${dom[$i]} ; exec bash"
        (( i += 1 ))
done

I hope this helps.

bakunin