korn shell for loops with expect issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting korn shell for loops with expect issue
# 1  
Old 07-10-2012
korn shell for loops with expect issue

Hi I have the following Korn script having multiple for loops.

PHP Code:
#!/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 13 14 15 16 17 18 19 20 21 22 23 ; do
for 
m in 00 30; do
for 
ent in nic board area ; do
$EXPECT << DONE
set stty_init raw
spawn dbisql 
-\"uid=dc\;pwd=dc\" -host 100.120.11.5 -port 2640 -nogui
expect "
>"
send "
insert into DC_RAW_01 \(nameOS_IDFDNENTRYSTATUSActivationUpdateSelfDeactivationCompletedActiv
ation
,TimeoutDeactivation,IdleTimeoutDeactivation,CompletedUpdateDATETIME_ID\) values (\'A$i\',\'Lin1\',\Doc,fix,A$i\',\'$ent\',\'UP\',
 4500, 8000, 15000, 1800, 12000, 17000, \'2012-06-$d $h:$m:00\'\)\r"
expect eof
close $fp
DONE
done
done
done
done
done 
Issue is when script runs for purpose of Insert statement, each time it runs spawn also, slowing down script execution. I have tried re-arraging for loops and spanw placing but have had no luck so far. Anyone see how to remove spawn after initial loop?
# 2  
Old 07-10-2012
How about this:

Code:
#!/bin/ksh
EXPECT=/usr/local/bin/expect
exp_internal
(
cat << EOF
set stty_init raw
spawn dbisql -c \"uid=dc\;pwd=dc\" -host 100.120.11.5 -port 2640 -nogui
EOF
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 13 14 15 16 17 18 19 20 21 22 23 ; do
for m in 00 30; do
for ent in nic board area ; do
cat << DONE
expect ">"
send "insert into DC_RAW_01 \(name, OS_ID, FDN, ENTRY, STATUS, Activation, Update, SelfDeactivation, CompletedActiv
ation,TimeoutDeactivation,IdleTimeoutDeactivation,CompletedUpdate, DATETIME_ID\) values (\'A$i\',\'Lin1\',\Doc,fix,A$i\',\'$ent\',\'UP\',
 4500, 8000, 15000, 1800, 12000, 17000, \'2012-06-$d $h:$m:00\'\)\r"
DONE
done
done
done
done
done
echo close $fp ) | $EXPECT

# 3  
Old 07-11-2012
This works a treat. 3 times faster now.
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

Two while loops with wget issue

Hello, When I run below script, everything is okay: #!/bin/bash wget --user-agent="Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0 referer" \ "http://xx.yy.zz/something" -O downloaded_file while read c1 do ... (6 Replies)
Discussion started by: baris35
6 Replies

2. Shell Programming and Scripting

Calling sqlplus from Korn shell heredoc issue

Hi, I am facing an issue wherein some temporary files (here docs) are getting created in /tmp and are not getting deleted automatically. When i check the list of open files with below command i can see one file is getting appended continuously.(In this case /tmp/sfe7h.34p) The output is... (4 Replies)
Discussion started by: Navin_Ramdhami
4 Replies

3. Shell Programming and Scripting

[Solved] Issue with using for loop as for in {2..6} in korn shell

Hi i have to cut columns 2 to 6 from a file and assign it to arrays , The following code works for ctcol in 2 3 4 5 6; do set -A a$ctcol $(cut -d, -f $ctcol test_file) done how ever this does not work for ctcol in {2..6}; do set -A a$ctcol $(cut -d, -f $ctcol test_file)... (4 Replies)
Discussion started by: 100bees
4 Replies

4. Shell Programming and Scripting

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: #!/bin/ksh EXPECT=/usr/local/bin/expect exp_internal i=1 h=0 while ]; do $EXPECT << DONE set stty_init raw ... (1 Reply)
Discussion started by: cic
1 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Korn Shell programming (FTP, LOOPS, GREP)

Hello All, I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database. To this, I have to construct a loop that checks a specified folder for a file. If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Discussion started by: jonesdk5
2 Replies

8. Shell Programming and Scripting

simple if/then issue in korn shell

When I run this, it tests to Y, but why? If I take the double quotes off of test, i get the same. # !/bin/ksh TEST="N" if ; then echo $TEST" yes" else echo "no" fi (4 Replies)
Discussion started by: guessingo
4 Replies

9. Shell Programming and Scripting

Unix Korn Shell Array Issue (SunOS)

Hello, I'm currently messing around with arrays for the first time in scripting (Unix Korn Shell). All I'm trying to do right now before I make things complicated is read through and print out to screen whether the read file is or is not a directory. Here is my directory: ls -l total... (5 Replies)
Discussion started by: Janus
5 Replies

10. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies
Login or Register to Ask a Question