multiple while loops in expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting multiple while loops in expect script
# 1  
Old 02-01-2012
multiple while loops in expect script

Hi,

I am trying to incorporate multiple while loops into an expect script written in ksh shell. This is on a Solaris 10 system. Here is the code:


Code:
#!/bin/ksh
  EXPECT=/usr/local/bin/expect
  exp_internal
   
  i=1
  h=0
  while [[ $i -le 9 && $h -le 23 ]]; do
   
  $EXPECT << DONE
  set stty_init raw
   
  spawn database_connect
  expect ">"
  send "insert into DB1 \(account, sum, DATETIME_
  ID\) values (\'BG0$i\', 100, \'2012-02-01 0$h:30:00\'\)\r"
  expect eof
  close $fp
  DONE
  ((i+=1))
  ((h+=1))
  done

So far the script loops with the 9 values for variable $i as desired.
However, not all values in range are looped for $h.
The while for $i runs to completion and increments $h with each iteration
Here is output of script so far:

./db.ksh[3]: exp_internal: not found
spawn database_connect
(db)> insert into DB1 (account, sum, DATETIME_ID) values ('BG01', 100, '2012-02-01 00:30:00')^M1 row(s) inserted
Execution time: 2.852 seconds

(db)> spawn database_connect

(db)> insert into DB1 (account, sum, DATETIME_ID) values ('BG02', 100, '2012-02-01 01:30:00')
:
:

I would like all instances of variable $h to be applied to $i while first loop runs:
BG01 - 00:30
BG01 - 01:30
BG01 - 23:30
:
:
BG09 - 23:30

Any ideas on where I can improve my while loops to accomplish?
# 2  
Old 02-16-2012
problem was not initialising variable after iteration at bottom of script:

Code:
Code:
DONE
  ((i+=1))   ((h+=1))   done
i=1
h=1


Last edited by Franklin52; 02-17-2012 at 03:07 AM.. Reason: Please use code tags for code and data samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

2. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

3. Shell Programming and Scripting

Help with multiple for loops

All, I have set up ssh trust between 3 machines. The aim is to connect from machine-A to B and C and clear the txt files in tmp on all 3 machines. And, I have 3 environments and each environment has 2 hosts. So I should be able to run this script on any environment. Here is the logic: I want... (5 Replies)
Discussion started by: pnara2
5 Replies

4. Shell Programming and Scripting

korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops. #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal for d in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 i22 23 24 25 26; do for i in 01 02 03 04 05 06 07 ; do for h in 00 01 02 03 04 05 06 07 08 09 10 11 12... (2 Replies)
Discussion started by: cic
2 Replies

5. Shell Programming and Scripting

Help With Expect Script IF with Multiple Conditions

I am needing to include some if statements within an expect script. These will need to have two conditions under an AND join. Upon a successful IF condition I want to set multiple variables. I have tried a lot of variations of the below statement with no success. I have also searched the WEB... (2 Replies)
Discussion started by: Slagathor
2 Replies

6. UNIX for Dummies Questions & Answers

While Loops Multiple File

Guru, I try to make a loop of 2 files, Input File1.txt: 1 2 File2.txt: A B C A, B and C is a file name, inside A X Y Z Expected Output A.1 X (2 Replies)
Discussion started by: guns
2 Replies

7. Shell Programming and Scripting

help with multiple loops in shell script

Hi Guys- I'm trying to write a script which takes date as input (mm.yy.dd) and search in the current file. If pattern doesn't exist it will then look in a backup directory and so on. being a newb i'm unable to loop over to the backup directory. hoping for some ideas, i've highlighted the... (1 Reply)
Discussion started by: Irishboy24
1 Replies

8. Shell Programming and Scripting

Expect script - going in loops can't stop

Hi First of all I tried lot of forums to create my first expect script. But I am totally stumped at the last step. I am no Linux Admin or ever trained in Linux. I just tried to create the script logically History : I need to to change my password across lot of servers in Linux over ssh ... (4 Replies)
Discussion started by: radioactive9
4 Replies

9. Shell Programming and Scripting

Expect While Loops - Partial Automation?

I've been reading the O'Reilley expect book and I'm trying to create partial automation for common questions asked on screen in a telnet session and return to interact so the user can resume control. For example while {1} { expect { -re "What color is the sky?" {send... (0 Replies)
Discussion started by: mlarivie
0 Replies

10. Shell Programming and Scripting

For loops with multiple variables

Hi script gurus. I have need to know how to use for loop with multiple variable. Basically lets take for example /etc/passwd file has following entries The above cat command will basically first greps the real users that have email addresses then converts ':' to '+' then using cut... (4 Replies)
Discussion started by: sparcguy
4 Replies
Login or Register to Ask a Question