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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Urgent..Help please....expect programs under while loop
# 1  
Old 03-17-2010
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 triggerred before the first one ends...also the loop commands are not executed for all data in the file(IP)

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 10:03 PM.. Reason: Code tags, please...
# 2  
Old 03-18-2010
Double post, continued here, thread closed.
# 3  
Old 03-18-2010
No double posting - see the forum rules. Also leave out stuff like "urgent" in future subjects please. There is an extra subboard here where you can post urgent requests following some procedure.

Thread closed, continue here:
https://www.unix.com/shell-programmin...hile-loop.html
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 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

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

6. Shell Programming and Scripting

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... (0 Replies)
Discussion started by: Hossam_Nox
0 Replies

7. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

8. Solaris

executing cgi programs in solaris(B89) needed urgent help,pls!

Hi all, I am trying to execute cgi scripts on solaris, but everytime i get a internal server error... The syntax of my .cgi script is correct as ive checked.. Steps i followed 1.started apache 2.The UNIX and Linux Forums - Learn UNIX and Linux from Experts (in opera) 3.places my cgi scripts... (7 Replies)
Discussion started by: wrapster
7 Replies

9. Shell Programming and Scripting

How to break the while loop???(Very Urgent)

H, I am running the following log.sh shell script. $no_of_ps=7 while do echo "hello $no_of_ps" ps_file=`tail -$no_of_ps /tmp/A380_RFS24/test.ls | head -1` no_of_ps=`expr $no_of_ps - 1` echo "package is: $ps_file" >> /tmp/A380_RFS24/log/A380_RFS24.log ps_file1=`echo $ps_file| sed... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

10. Shell Programming and Scripting

Urgent:Comparing two Strings using If Loop

Hi All, Please help me out in this... I am new to scripting How to compare two strings by using the same string in single loop, I am using ksh for ex:see the code snippet below I am writing in java, Can u guys tell me that in scripting if ("string1"=="string2" ||... (2 Replies)
Discussion started by: Anji
2 Replies
Login or Register to Ask a Question