Sponsored Content
Top Forums Shell Programming and Scripting Urgent..Help please....expect programs under while loop Post 302404985 by Hossam_Nox on Wednesday 17th of March 2010 06:31:53 PM
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...
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
after(n)						       Tcl Built-In Commands							  after(n)

__________________________________________________________________________________________________________________________________________________

NAME
after - Execute a command after a time delay SYNOPSIS
after ms after ms ?script script script ...? after cancel id after cancel script script script ... after idle ?script script script ...? after info ?id? _________________________________________________________________ DESCRIPTION
This command is used to delay execution of the program or to execute a command in background sometime in the future. It has several forms, depending on the first argument to the command: after ms Ms must be an integer giving a time in milliseconds. The command sleeps for ms milliseconds and then returns. While the command is sleeping the application does not respond to events. after ms ?script script script ...? In this form the command returns immediately, but it arranges for a Tcl command to be executed ms milliseconds later as an event handler. The command will be executed exactly once, at the given time. The delayed command is formed by concatenating all the script arguments in the same fashion as the concat command. The command will be executed at global level (outside the context of any Tcl procedure). If an error occurs while executing the delayed command then the background error will be reported by the com- mand registered with interp bgerror. The after command returns an identifier that can be used to cancel the delayed command using after cancel. after cancel id Cancels the execution of a delayed command that was previously scheduled. Id indicates which command should be canceled; it must have been the return value from a previous after command. If the command given by id has already been executed then the after can- cel command has no effect. after cancel script script ... This command also cancels the execution of a delayed command. The script arguments are concatenated together with space separators (just as in the concat command). If there is a pending command that matches the string, it is cancelled and will never be executed; if no such command is currently pending then the after cancel command has no effect. after idle script ?script script ...? Concatenates the script arguments together with space separators (just as in the concat command), and arranges for the resulting script to be evaluated later as an idle callback. The script will be run exactly once, the next time the event loop is entered and there are no events to process. The command returns an identifier that can be used to cancel the delayed command using after can- cel. If an error occurs while executing the script then the background error will be reported by the command registered with interp bgerror. after info ?id? This command returns information about existing event handlers. If no id argument is supplied, the command returns a list of the identifiers for all existing event handlers created by the after command for this interpreter. If id is supplied, it specifies an existing handler; id must have been the return value from some previous call to after and it must not have triggered yet or been cancelled. In this case the command returns a list with two elements. The first element of the list is the script associated with id, and the second element is either idle or timer to indicate what kind of event handler it is. The after ms and after idle forms of the command assume that the application is event driven: the delayed commands will not be executed unless the application enters the event loop. In applications that are not normally event-driven, such as tclsh, the event loop can be entered with the vwait and update commands. EXAMPLES
This defines a command to make Tcl do nothing at all for N seconds: proc sleep {N} { after [expr {int($N * 1000)}] } This arranges for the command wake_up to be run in eight hours (providing the event loop is active at that time): after [expr {1000 * 60 * 60 * 8}] wake_up The following command can be used to do long-running calculations (as represented here by ::my_calc::one_step, which is assumed to return a boolean indicating whether another step should be performed) in a step-by-step fashion, though the calculation itself needs to be arranged so it can work step-wise. This technique is extra careful to ensure that the event loop is not starved by the rescheduling of processing steps (arranging for the next step to be done using an already-triggered timer event only when the event queue has been drained) and is useful when you want to ensure that a Tk GUI remains responsive during a slow task. proc doOneStep {} { if {[::my_calc::one_step]} { after idle [list after 0 doOneStep] } } doOneStep SEE ALSO
concat(n), interp(n), update(n), vwait(n) KEYWORDS
cancel, delay, idle callback, sleep, time Tcl 7.5 after(n)
All times are GMT -4. The time now is 02:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy