Script to iterate over several options


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Script to iterate over several options
# 1  
Old 03-19-2019
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

Code:
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
Moderator's Comments:
Mod Comment code tags please




Please advise

Last edited by jim mcnamara; 03-19-2019 at 11:43 AM..
# 2  
Old 03-19-2019
Welcome to the forum.


Any attempts / ideas / thoughts from your side?


What does "two 3 files" mean when you show just one sample file?
# 3  
Old 03-19-2019
Moderator's Comments:
Mod Comment Please use meaningful thread titles. "Shell Script:" is NOT meaningful in a subforum for shell scripting. (Hint: "Thread" or "Question" would be not meaningful either.)


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

Code:
dom = dom1 "this is dom2" dom3

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

I hope this helps.

bakunin
# 4  
Old 03-19-2019
Code:
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

# 5  
Old 03-20-2019
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
# 6  
Old 03-20-2019
Quote:
Originally Posted by abhaydas
... solution suggested by Corona688 worked for me.
...
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?
# 7  
Old 03-22-2019
It was 3 files , two was a typo
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Iterate over `dirs` in a bash script

I would like to iterate over `dirs`in a script, but the script will never show more than one (current) folder #! /bin/bash for i in `dirs` do echo ${i} done echo ++++++++++++++++++ for i in $( dirs -p ) do echo ${i} done echo ------------------ dirscontent=`dirs` echo... (5 Replies)
Discussion started by: alexanderb
5 Replies

2. UNIX for Dummies Questions & Answers

Script to iterate all command line arguments

Hi guys, I am having trouble with this script. What i want it to do is to iterate all command line arguments in reverse order. The code below does this fine but i need the output to print the words on separate lines instead of one line: #!/bin/bash #Takes in the arguments and displays them... (7 Replies)
Discussion started by: pipeline2012
7 Replies

3. Shell Programming and Scripting

script to iterate

Hi i need to find x in the following equation such that it satisfies this condition: y/x-ln(x)-1.24=0 how can i write a script to iterate to give random x to satisfy this equation. y is different each time too. any help with awk/shell script will be awesome! thanks (1 Reply)
Discussion started by: saint2006
1 Replies

4. Shell Programming and Scripting

shell script options

one thing i was trying to figure out is if you can give people the option to choose what they want to do in a shell script. for example, let's just say that you have a simple shell script to install a couple of programs, can you make it to where you can press a certain key to install a certain... (1 Reply)
Discussion started by: hotshot247
1 Replies

5. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

6. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies

7. Shell Programming and Scripting

Passing options into a script

Afternoon all, I have been writing a script to do some selects on a table dependent on what options are selected when the script is run: #!/bin/ksh set -x set -m if then echo "usage: msglog.ksh -da <date and time> -i <interface> -m <msg> -di <direction> -mi <MIR>" exit 1 fi... (3 Replies)
Discussion started by: chris01010
3 Replies

8. Shell Programming and Scripting

Help with options and arguments to a script

I'm trying to write a script that accepts both arguments and options, e.g. ./script -h 1 -m 15 -s 30 or ./script -h 1 -m 15 -s 30 I'd like for any of the arguments and options to be optional, and the option values should be numerals only. I've tried both getopt and getopts but I... (1 Reply)
Discussion started by: Ilja
1 Replies

9. UNIX for Dummies Questions & Answers

Iterate a min/max awk script over time-series temperature data

I'm trying to iterate a UNIX awk script that returns min/max temperature data for each day from a monthly weather data file (01_weath.dat). The temperature data is held in $5. The temps are reported each minute so each day contains 1440 temperature enteries. The below code has gotten me as far as... (5 Replies)
Discussion started by: jgourley
5 Replies
Login or Register to Ask a Question