Re: script does not always work the same each time.
- From: Glenn Jackman <glennj@xxxxxx>
- Date: 9 May 2008 18:02:38 GMT
[I didn't trim original post, scroll down]
At 2008-05-09 12:54PM, "netskink" wrote:
Hello
I have written a simple script to test code build and test run on a
remote server. I intend to have the script read form a file a list of
host names so I can do a bunch of automatic regression testing. The
code consists of a driver and application. I need to check if the
driver failed to build, the application failed to build, or the progam
failed to run.
The problem is that the expect script does not always work. Most
times it will detect a failure in buildig either the driver or the app
and a problem with running the app. But, sometimes it will miss the
failure mesage. here is an example of a failure in the expect script.
root@debian:~/winDesktop/work/expect# ./ssh.exp
spawn ssh aki
root@aki's password:
Last login: Fri May 9 12:18:40 2008 from 10.254.247.248
[root@aki root]# cd davis/dbgdriver
[root@aki dbgdriver]# ./build.sh
Platform table is valid.
Attempting to build driver.
Running make for 2.4 kernel.
gcc -D__KERNEL__ -DKERNEL24 -DMODULE -I/usr/src/linux-2.4.20-8/include
-O -Wall -c -o dbgdriver.o dbgdriver.c
In file included from /usr/src/linux-2.4.20-8/include/asm/spinlock.h:
4,
from /usr/src/linux-2.4.20-8/include/linux/spinlock.h:
56,
from /usr/src/linux-2.4.20-8/include/linux/module.h:
11,
from dbgdriver.c:11:
/usr/src/linux-2.4.20-8/include/asm/atomic.h:22: syntax error before
"typedef"
make: *** [dbgdriver.o] Error 1
Failed to build driver using 2.4 Makefile.
[root@aki dbgdriver]# ./myapp7
-bash: ./myapp7: No such file or directory
[root@aki dbgdriver]#
If failed to see the "Failed to build driver" line.
Here is the code:
#!/usr/bin/expect -f
set ssh_command "ssh aki"; # since this is more than 1 word, use eval
set prompt "# "; # our shell prompt
#log_user 0
eval spawn $ssh_command
set lineterminationChar "\r"
expect {
"*password: " { send "Passw0rd\r"; }
$lineterminationChar { append output $expect_out(buffer);
exp_continue }
eof { append output $expect_out(buffer)}
}
expect {
$prompt { send "cd davis/dbgdriver\r"; }
$lineterminationChar { append output $expect_out(buffer);
exp_continue }
eof { append output $expect_out(buffer)}
}
expect {
$prompt { send "./build.sh\r"; }
"Failed*" { send_user "***** FAILURE ****\n\r";
exit 1; }
$lineterminationChar { append output $expect_out(buffer);
exp_continue }
eof { append output $expect_out(buffer)}
}
expect {
$prompt { send "./myapp7\r"; }
"Failed*" { send_user "***** FAILURE ****\n\r";
exit 1; }
$lineterminationChar { append output $expect_out(buffer);
exp_continue }
eof { append output $expect_out(buffer)}
}
expect {
"Physical Address of iSize*"
{ send_user "***** PASS ****\n\r";
exit 0; }
$lineterminationChar { append output $expect_out(buffer);
exp_continue }
eof { append output $expect_out(buffer)}
}
# something weird happened. Look into it.
interact;
I'm not sure what you're doing with $output. You'd probably be better
off replacing it with [log_file]. I'd write your script like this:
#!/usr/bin/expect -f
set ssh_command "ssh aki"
set prompt "# "
eval spawn $ssh_command
log_file myoutput.out
expect_after {
eof {
# do something extra before exiting?
send_user "***** EOF FOUND ****\n"
exit
}
}
expect "*password: "
send "Passw0rd\r"
expect -re "$prompt$"
send "cd davis/dbgdriver\r"
expect -re "$prompt$"
send "./build.sh\r"
expect {
"\r\nFailed*" {
send_user "***** BUILD FAILURE ****\n"
exit 1
}
-re "$prompt$"
}
send "./myapp7\r"
expect {
"\r\nFailed*" {
send_user "***** MYAPP FAILURE ****\n"
exit 1
}
"Physical Address of iSize*" {
send_user "***** PASS ****\n"
exit 0
}
}
# something weird happened. Look into it.
interact
--
Glenn Jackman
"If there is anything the nonconformist hates worse than a conformist,
it's another nonconformist who doesn't conform to the prevailing
standard of nonconformity." -- Bill Vaughan
.
- Follow-Ups:
- Re: script does not always work the same each time.
- From: netskink
- Re: script does not always work the same each time.
- From: netskink
- Re: script does not always work the same each time.
- References:
- script does not always work the same each time.
- From: netskink
- script does not always work the same each time.
- Prev by Date: script does not always work the same each time.
- Next by Date: Special Track “Computational Bioimaging and Visualization” within the ISVC08 USA - Announce & Call for Papers
- Previous by thread: script does not always work the same each time.
- Next by thread: Re: script does not always work the same each time.
- Index(es):
Relevant Pages
|
|