Re: script does not always work the same each time.



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



Relevant Pages

  • script does not always work the same each time.
    ... I have written a simple script to test code build and test run on a ... code consists of a driver and application. ... $lineterminationChar {append output $expect_out; ...
    (comp.lang.tcl)
  • Re: automating a remote build and test of code.
    ... $lineterminationChar {append output $expect_out; ... exit 1;} ... Attempting to build driver. ...
    (comp.lang.tcl)
  • Re: Changing a users password non-interactively?
    ... You need expect and a setpass.expect script which ill add ... exit with a nasty warning. ... # Be careful of the COMMAND and UNDOCMD - they are dependant on your ...
    (comp.unix.aix)
  • Re: OSR505 Signal trapping in shell scripts
    ... >>My test script is at the end. ... > process only gets one SIGHUP per fd. ... > end up doing ioctls on fd 0, which is your stopio'd telnetd pty. ... > of the exit function. ...
    (comp.unix.sco.misc)
  • Re: How to time out a command
    ... > I have a ksh script that calls another utility (command A). ... I once made the following script to do exactly that. ... # Runs a command and kills it, if necessary, after a given timeout. ... # 0<c<127 - job exited with this exit code ...
    (comp.unix.shell)