Running scripts from a list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running scripts from a list
# 1  
Old 10-09-2012
Running scripts from a list

I am writing a bash script to run test some scripts.

The names scripts of the scripts to tests are stored in an array.

Code:
scptArr[1]='chcksfrd.bash' 
scptArr[2]='compute-misfit.bash' 
scptArr[3]='compute-travel-times.bash' 
scptArr[4]='create-data-tinv.bash' 
scptArr[5]='create-docs.bash' 
scptArr[6]='create-model.bash' 
scptArr[7]='darwin-ga.bash' 
scptArr[8]='listdir.bash' 
scptArr[9]='plot-misfit.bash' 
scptArr[10]='plot-model.bash' 

When the user inputs a number, 7 say, I run the appropriate script in the array, for example:

Code:
darwin-ga.bash -h



This I do using
Code:
scptArr[$inum] -h

I now would like that when a user enters a range, for example, 5-7,
I run the appropriate scripts supplied by the user numbers.

I would also like to have sequences such as

Code:
2,5-7,10,12,15-19,20,22,25


Last edited by kristinu; 10-09-2012 at 08:11 AM..
# 2  
Old 10-09-2012
There are no prefabricated, ready-to-run solutions for this. You will have to write your own. Write a small parser and tokenize/parse the input.

Tokenizing means to cut the input into small, manageable pieces. Lets say, a "token" can be:

1. a number - this starts the script with this number

2. a range - this starts one script starting with the first number and ending with the last number.

ok. A "number" is: any numeric value for which an item in the array can be found, followed by either a comma "," or the line end.

A "range" is: a number, followed by a dash, followed by a number, followed by a a comma or line end.

The first part of the script will "read" the input up to the next delimiter (end-of-line or comma and use this as the next token.When the script has successfully found a token remove that from the input line.

Remove the delimiter character from the token and send it to a long case-branch where the various tokens are handled. Pseudo-code ("n" represents a number/array index here, notice that the last four entries are badly formatted or of wrong datatype - the script has to be able to cope with this and come up with a proper error message):

Code:
input="n,n-n,n-,-n,n-n-n,the-endisnear"

remaining_line=input

while( remaining_line != "" )
     token=get_next_token(remaining_line)
     remaining_line=remaining_line - token
     case token in
          <number>)
               if( number within array bounds )
                    exec ${array[$number]}
               else
                    ERROR: number entered not within bounds
               end if
               ;;

          <number>-<number>)
               PASS=OK
               if( NOT num1 within array bounds )
                    ERROR: num1 not within bounds
                    PASS=not_OK
               end if
               if( NOT num2 within array bounds )
                    ERROR: num2 not within bounds
                    PASS=not_OK
               end if
               if( PASS == OK )
                    for( i=num1,i=num2,i++ )
                         exec ${array[$number]}
                    next
               end if
               ;;

          <number>-)
               ERROR: range clause not properly closed
               // you might want to change this to mean "from num to the end"
               ;;

          -<number>)
               ERROR: range clause not properly opened
               // you might want to change this to mean "from 1 to num"
               ;;

          all others)
               ERROR: cannot understand <token>
               ;;

     end case
end while

I hope this helps.

bakunin
# 3  
Old 10-09-2012
Ok, now I have coded the following to get all the separate tags

Code:
str="2,4,6,10-15,21,25"
tags=`echo $str | awk '{gsub(/,/," ")}; {print}'`
echo "tags = $tags"
i=0
for t in $tags
do
  i=$((i+1))
  echo "$i: $t"
done

I now have to expand the ranges i-j.

---------- Post updated at 10:26 AM ---------- Previous update was at 08:28 AM ----------

Code:
str="2,4,6,10-15,21,25"
tags=`echo $str | awk '{gsub(/,/," ")}; {print}'`
echo "tags = $tags"
i=0
for t in $tags
do
  i=$((i+1))
  echo "$i: $t"
  match=`echo $t | grep "-"`
  if [ ${#match} -gt 0 ]; then
      ia=`echo $match | awk 'BEGIN {FS="-"} {print $1}'`
      ib=`echo $match | awk 'BEGIN {FS="-"} {print $2}'`
      echo "match = $match, ia = $ia, ib = $ib"
  fi
done

Now I have the start and end numbers for the ranges being stored
in 'ia' and 'ib'.

Need now to create the range between ia and ib.

For example, if ia=5 and ib=8, need to generate the sequence
5 6 7 8
# 4  
Old 10-10-2012
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Running scripts from different server

Hi, I need a script (ksh) on ServerAdmin that will run an archive scripts from different several Servers through ssh. The problem is that how can i switch user when before running the archive script. I already configured password-less connection on the servers. server 1... (1 Reply)
Discussion started by: chococrunch6
1 Replies

2. Shell Programming and Scripting

running scripts in minicom

Hi, I am new to use minicom. I want script to run on minicom with username and password as automated.(Expect). please could anyone suggest the sample code for it. Thanks in advance (2 Replies)
Discussion started by: vanid
2 Replies

3. Shell Programming and Scripting

Running 2 scripts one after the other using cron

I would like to run two scripts using cron one immediately after the other. Is it enough to put them one after another in the cron file to run at the same time, or will this cause them to run concurrently? (4 Replies)
Discussion started by: 3210
4 Replies

4. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

5. Shell Programming and Scripting

Running scripts via su

Hi All, Am using the below command to start my application using the root user su - bin -c "/home/bin/test/start.sh" but am getting the error becaue i have set some environment varibales in bin .profile when i execute the command start.sh by logging directly into bin account it's... (8 Replies)
Discussion started by: ravi.sri24
8 Replies

6. UNIX for Dummies Questions & Answers

Automatically Running Scripts

Can someone advise me how to get started automatically running scripts? I believe it has something to do with cron? (4 Replies)
Discussion started by: jeffreydavisjr
4 Replies

7. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/prd_pre_to_post.sh 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

8. Shell Programming and Scripting

running multiple scripts

Hi all I have a requirement where I have a flow like Script1 script2 Script3 Script 4 Script 5 Script 6 script7 where script2 to script6 will... (3 Replies)
Discussion started by: nvuradi
3 Replies

9. UNIX for Dummies Questions & Answers

Running scripts parallely

Hi, Posting my first query in this Forum,here's my query i want to execute 100 .sql files in unix having some code for connecting with db and executing procedures inside that,that to be run parallel like threads.want to run all the 100 .sql files simultanously. thanks in advance. (4 Replies)
Discussion started by: santho
4 Replies

10. Shell Programming and Scripting

Running three scripts parallelly

Hi All, We have three shell script batch, which extract data from three different systems(oracle, db2, db2/400). By running each shell script batch, the data is extracted from respective systems. while the batch is running, job date, system_name, start_date and end_date will be inserted into... (1 Reply)
Discussion started by: anwarsait
1 Replies
Login or Register to Ask a Question