expect file under while loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect file under while loop
# 1  
Old 03-17-2010
expect file under while loop

Hello....

I'm developing a script; the first step is to create a file (its name is IP) which contains several lines. The second step is to create and execute expect programs using the data in the (IP) file.

Unfortunately, the loop is executed using the first line only not all the lines and suddenly the execution ends.

The main program is

Code:
#!/bin/ksh
#=============================================================================
# This script checks the following:
#  If Active OMCP is synchronized with the NTP source (usually OMC-R)
#  If Other Boards of MX BSC are NTP synchronized with the active OMCP
#  
#
# Valid for BSS versions B9 & B10
#
# Author: Hossam Gad
#=============================================================================

cp /alcatel/omc3/bsscomm/data/mib.ip.decl /alcatel/var/share/AFTR/MISC
cd /alcatel/var/share/AFTR/MISC
sed '/^$/d' mib.ip.decl > draft1
sed -e '1,15d' draft1 > draft2
cut -f2 draft2 > IDdraft
cut -f5 draft2 > IPdraft
sed -e '2d;n;d' IDdraft > ID
sed -e '1d;n;d' IPdraft > IP
while read line
do
echo "#!/usr/local/bin/expect" > program_$line.expect
echo "#!/usr/local/bin/expect" > ftp_$line.expect
echo "set line $line" >> program_$line.expect
echo "set line $line" >> ftp_$line.expect
cat program >> program_$line.expect
cat ftp >> ftp_$line.expect
expect -f program_$line.expect
expect -f ftp_$line.expect
cut -f1 time_difference_OMCPactive >> Active_OMCP
rm time_difference_OMCPactive
done < IP
echo "BSS IDs" > IDs
echo "------" >> IDs
echo "  BSS IPs" > IPs
echo "---------" >> IPs
echo "Active OMCP Drift" > D_ACT_OMCP
echo "---------" >> D_ACT_OMCP
cut -f1 ID >> IDs
cut -f1 IP >> IPs
cut -f1 Active_OMCP >> D_ACT_OMCP
paste IDs IPs D_ACT_OMCP > NTPDRIFT.log
#rm draft1 draft2 IDdraft IPdraft *time_difference* *Active_OMCP* IDs IPs D_ACT_OMCP
cat NTPDRIFT.log

 
program:
spawn ssh mxadmin@$line 
expect {
"yes/no" {send "yes\r"}
}
expect "Password:"
send  "mxadmin\r"
sleep 5
send "su - root\r"
expect "Password:"
send "alcatel\r"
send "/usr/local/NTP/scripts/ntp_supervision.sh -test\r"
send "cp /usr/local/NTP/sup/time_difference /tmp/time_difference_OMCPactive\r"
send "exit\r" 
send "exit\r"
interact
 
ftp:
spawn sftp mxadmin@$line 
expect {
"yes/no" {send "yes\r"}
}
expect "Password:"
send  "mxadmin\r"
expect "sftp>"
send "cd /tmp\r"
expect "sftp>"
send "get time_difference_OMCPactive\r"
expect "sftp>"
send "bye\r"
interact


Last edited by Scott; 03-17-2010 at 06:58 PM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect Script - Not Seeing Output from While Loop

I know something simple is missing here, "log_user 1" is set . . . after this utility opens ${InFile} (handle? for IntInFile) it needs to look for something to appear in the file ${IntInFile} and then send it to the spawned process. Then I am locking the file ${IntInFile} and clearing it out -... (0 Replies)
Discussion started by: JuanMatteo
0 Replies

2. Shell Programming and Scripting

How to run the following expect commands in a loop?

spawn fbat expect ">>" send "log fbatPW80_OR8sim1 \r" expect ">>" send "load map.map \r" expect ">>" send "load fbatPW80_OR8sim1.ped \r" expect ">>" send "fbat -v1 \r" expect ">>" send "log off \r" expect ">>" I need the above code to run in a loop such that script keeps doing a... (1 Reply)
Discussion started by: zoeli
1 Replies

3. Shell Programming and Scripting

How to extract an ipaddress and use it in for loop in expect script?

set fid set content close $fid ## Split into records on newlines set records send "records splited\n" send $records\n set a "test\n" send $a foreach rec $records { ## Split into fields on colons set fields #set fields puts $fields for {set x 1} {$x < 4} {incr x} {... (1 Reply)
Discussion started by: rachanaPatel
1 Replies

4. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

5. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

6. Shell Programming and Scripting

Expect script called in loop from Bash Script

Having issues with an expect script. I've been scripting bash, python, etc... for a couple years now, but just started to try and use Expect. Trying to create a script that takes in some arguments, and then for now, just runs a pwd command(for testing, final will be command I pass). Here is... (0 Replies)
Discussion started by: cbo0485
0 Replies

7. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

8. Shell Programming and Scripting

How to run the following expect commands in a loop

#!/usr/bin/expect spawn telnet 1.1.1.1 expect login* send “admin\r” expect Password* send “abcdef123\r” expect “Router#” send “exit\r” I want the above code to run in a loop such that script keeps doing a telnet to the device. Please suggest Tarun (1 Reply)
Discussion started by: tkhanna82
1 Replies

9. Shell Programming and Scripting

Expect - Comparison of expect value and loop selection

Hello All, I am trying to automate an installation process using expect and sh script. My problem is that during the installation process the expected value can change according to the situation. For Example if this is a first time installation then at step 3 I'll get "Do you want to accept... (0 Replies)
Discussion started by: alokrm
0 Replies

10. Shell Programming and Scripting

Urgent..Help please....expect programs under while loop

Hello.... I'm developing a script; the first step is to create a file (its name is IP) which contains several lines. The second step is to create and execute expect programs using the data in the (IP) file. Unfortunately, the loop is not executed properly....sometimes, the 2nd expect file is... (2 Replies)
Discussion started by: Hossam_Nox
2 Replies
Login or Register to Ask a Question