Script to iterate over several options


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

Code:
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
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
LOCKTEST(1)							  [FIXME: manual]						       LOCKTEST(1)

NAME
locktest - Find differences in locking between two SMB servers SYNOPSIS
locktest {//server1/share1} {//server2/share2} [-U user%pass] [-U user%pass] [-s seed] [-o numops] [-a] [-O] [-E] [-Z] [-R range] [-B base] [-M min] DESCRIPTION
locktest is a utility for detecting differences in behaviour in locking between SMB servers. It will run a random set of locking operations against //server1/share1 and then the same random set against //server2/share2 and display the differences in the responses it gets. This utility is used by the Samba team to find differences in behaviour between Samba and Windows servers. OPTIONS
-U user%pass Specify the user and password to use when logging on on the shares. This parameter can be specified twice (once for the first server, once for the second). -s seed Seed the random number generator with the specified value. -o numops Set the number of operations to perform. -a Print the operations that are performed. -A Backtrack to find minimal number of operations required to make the response to a certain call differ. -O Enable oplocks. -u Hide unlock fails. -E enable exact error code checking -Z enable the zero/zero lock -R range set lock range -B base set lock base -M min set min lock length -k Use kerberos VERSION
This man page is correct for version 4.0 of the Samba suite. SEE ALSO
Samba AUTHOR
This utility is part of the Samba[1] suite, which is developed by the global Samba Team[2]. locktest was written by Andrew Tridgell. This manpage was written by Jelmer Vernooij. NOTES
1. Samba http://www.samba.org/ 2. Samba Team http://www.samba.org/samba/team/ [FIXME: source] 04/16/2014 LOCKTEST(1)