Reputation: 173
I have part of expect script, which is connecting to remote server, and running command /opt/arne/bin/import.sh -f /home/janko496/moshell/test.xml -val:rall
. So basicily it is doing ok, but what I need is catch some errors which may happen after this command -vall-rall
and then exit.
Here is the log of the script when is runned:
janko496@rtwauas1o> perl ex
*************************************************************
* /// START /// *
*************************************************************
spawn ssh mashost
Password:
Your password will expire in 15 days.
Last login: Mon Jan 26 09:51:52 2015 from rtwauas1o
janko496@rtwaadmin1o> cd /home/janko496/moshell
janko496@rtwaadmin1o> /opt/arne/bin/import.sh -f /home/janko496/test.xml -val:rall
Logging to file /var/opt/arne/ARNE_Import_Log.2015-01-26_09:54:12
-------------------------------------------------------------------------------
MUG does not support the delete upgradation operation.
-------------------------------------------------------------------------------
Validating XML File.....
Delete XML files are only validated for DTD and limited semantic errors.....
Finished validating file /home/janko496/test.xml
There were 0 errors reported during validation
janko496@rtwaadmin1o> /opt/arne/bin/import.sh -f /home/janko496/test.xml -import
Logging to file /var/opt/arne/ARNE_Import_Log.2015-01-26_09:54:23
-------------------------------------------------------------------------------
MUG does not support the delete upgradation operation.
-------------------------------------------------------------------------------
Starting Import..
Progress :7%:Validating against mandatory rules for 'siu064842'
Progress :15%:Adjusting with NEC for 'siu064842'.
Progress :23%:Deleted Target Information.
Progress :30%:Deleting Object 'SubNetwork=NL1,SubNetwork=EHWOUR_SIU,ManagedElement=siu064842'.
Progress :38%:Action Committed
Progress :46%:Object fully deleted.
Progress :53%:Adjusting with NEC for 'siu064842'.
Progress :61%:Transaction committed, updating Area.
Progress :100%:Temporary Area Deleted.
Import Finished.
No Errors Reported.
and here is the script:
set strname There were 0 errors reported during validation
spawn ssh mashost
#exp_internal 1
expect {
"assword" {send "$PASSWORD\r"}
}
set timeout 100
expect "janko496@rtwaadmin1o"
send -- "cd /home/janko496/moshell\r"
expect "janko496@rtwaadmin1o"
send -- "/opt/arne/bin/import.sh -f /home/janko496/moshell/test.xml -val:rall \r"
if { [string compare expect_out(0,string) strname ] != 1 } {
send "exit\r";
}
send -- "/opt/ericsson/arne/bin/import.sh -f /home/janko496/test.xml -import \r"
expect "janko496@rtwaadmin1o"
so I want to catch this string "There were 0 errors reported during validation
and continue or exit if there are some error's.
Upvotes: 0
Views: 390
Reputation: 137557
You want an expect
that waits for two different things at once after the:
send -- "/opt/arne/bin/import.sh -f /home/janko496/moshell/test.xml -val:rall \r"
The two things that you are waiting for are for a pattern that indicates success and a pattern that indicates failure. Note that using a regular expression pattern (-re
) can help a lot with this, and regular expressions should (normally) be put in braces:
expect {
"There were 0 errors reported during validation" {
puts "Yay, validation succeeded"
# You don't really need to put very much in here...
}
-re {There were (\d+) errors reported during validation} {
puts "Found $expect_out(1,string) errors in validation"
send "exit\r"
after 100
close
exit
}
}
Upvotes: 1