シリアル接続とexpectコマンドで、処理の自動化。

expectコマンドなら入力を自動化できるので、それを使ってhackbenchを動かして終了するスクリプトを書いてみた。
expectのスクリプトはこんな感じで。

[masami@moonlight:~/kvm-img]% cat test.sh
#!/usr/bin/expect --

set timeout 600

spawn  kvm -hda lenny.img  -m 512 -monitor stdio -boot c -serial stdio
expect "lenny login:"
send "root\n"

expect "Password:"
send "password\n"

expect "lenny:~#"
send "uname -a\n"

expect "lenny:~#"
send "/usr/local/src/autotest/autotest-0.11.0/client/bin/autotest /usr/local/src/autotest/autotest-0.11.0/client/tests/hackbench/control\n"

expect "lenny:~#"
send "shutdown -h now\n"

expect "The system is going down for system halt NOW!"

exit

これを実行してみる。

[masami@moonlight:~/kvm-img]% ./test.sh    
spawn kvm -hda lenny.img -m 512 -monitor stdio -boot c -serial stdio

Debian GNU/Linux 5.0 lenny ttyS0

lenny login: root
Password: 
Last login: Sun Dec 13 23:06:16 JST 2009 on ttyS0
Linux lenny 2.6.32 #1 SMP Sat Dec 12 09:11:15 JST 2009 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
lenny:~# uname -a
Linux lenny 2.6.32 #1 SMP Sat Dec 12 09:11:15 JST 2009 x86_64 GNU/Linux
src/autotest/autotest-0.11.0/client/tests/hackbench/control/autotest /usr/local/ 
DEBUG:root:Cleaning up previously found state file
23:12:10 INFO | Writing results to /usr/local/src/autotest/autotest-0.11.0/client/results/default
23:12:10 INFO | Initializing the state engine
23:12:10 INFO | Symlinking init scripts
23:12:10 INFO | START	----	----	timestamp=1260713530	localtime=Dec 13 23:12:10	
23:12:10 INFO | 	START	hackbench	hackbench	timestamp=1260713530	localtime=Dec 13 23:12:10	
23:12:10 INFO | Test started. Number of iterations: 1
23:12:10 INFO | Executing iteration 1 of 1
23:17:22 INFO | Test finished after 1 iterations.
23:17:22 INFO | 		GOOD	hackbench	hackbench	timestamp=1260713842	localtime=Dec 13 23:17:22	completed successfully
23:17:22 INFO | 	END GOOD	hackbench	hackbench	timestamp=1260713842	localtime=Dec 13 23:17:22	
23:17:22 INFO | END GOOD	----	----	timestamp=1260713842	localtime=Dec 13 23:17:22	
lenny:~# shutdown -h now

Broadcast message from root@lenny (ttyS0) (Sun Dec 13 23:17:22 2009):

The system is going down for system halt NOW!
[masami@moonlight:~/kvm-img]%