Expect script not working

Dell Studio laptop with intel core 2 duo...
May 27, 2010 at 06:11:22
Specs: SunOS 5.10
Hi friends,

I am trying to write an expect script for the first time.
My purpose is to automate the recycle of one app.
When give the stop-domain command it asks for password. Same with start domain.
I wrote a separate expect script which i would call from shell script.
But when i test the script it gives error.
The expect script for stop is as below.

#! /usr/local/bin/expect
########################################################
#This is an expect file to run to stop the glassfish
#File name : stopGlassfish.expect
#######################################################
spawn stopGlassfish.expect
send "su - passme -c \"cd /appl/site/Glassfish/glassfish/bin;asadmin stop-domain bdacert\" >& glassfishRecycle.log\n"
expect "Password: \n"
send "passme\n"
interact

This results in the o/p below.
sh: /usr/local/bin/stty: not found
su - passme -c "cd /appl/site/Glassfish/glassfish/bin;asadmin stop-domain bdacert" >& glassfishRecycle.log

And this o/p comes in an infinite loop unless i press ctrl C.

when i comment the line spawn in the script I get the below.
dev546789% stopGlassfish.expect
su - passme -c "cd /appl/site/Glassfish/glassfish/bin;asadmin stop-domain bdacert" >& glassfishRecycle.log
passme
cannot interact with self - set spawn_id to a spawned process
while executing
"interact"
(file "stopGlassfish.expect" line 10)


Could you please help me identify what is the problem.

FYI this is C SHELL

Thanks for your help!


See More: Expect script not working

Report •

#1
May 27, 2010 at 13:26:45
I am not much of an expect person, but if you are executing the su - ... command from your expect script, shouldn't you be spawing the su command - not sending it?


Report •

#2
May 28, 2010 at 05:06:35
You are absolutely r8 nails.Thanks
I wish I could have checked this before working all night on this. :-)
Anyways here goes what i did.
2 expect files would be called from the shell script.
So total 3 scripts.
This may help someone with similar requirements.
More efficient methods are welcome also.

1.startGlassfish.expect

#! /usr/local/bin/expect -f
########################################################
#This is an expect file to run to stop the glassfish
#File name : startGlassfish.expect
#######################################################
spawn su - user
expect "Password: "; send "passme\n"
send "cd XXXX/YYYYY/ZZZZZ; scriptstart.sh arg1 arg2\n"
expect "$"
send "exit\n"
interact

2.stopGlassfish.expect

#! /usr/local/bin/expect -f
########################################################
#This is an expect file to run to stop the glassfish
#File name : stopGlassfish.expect
#######################################################
spawn su - user
expect "Password: "; send "passme\n"
send "cd XXXX/YYYYY/ZZZZZ; scriptstop.sh arg1 arg2\n"
expect "$"
send "exit\n"
interact

3.GlassFishRecycle.sh

#! /bin/csh
###################################################################
#Script name: GlassFishRecycle.sh
#This script is designed to automate the Glassfish Recycle process
###################################################################
stopGlassfish.expect >glassfishRecycle.log
if (`grep "Glassfish stopped." glassfishRecycle.log |wc -l` != 0) then
startGlassfish.expect >>glassfishRecycle.log
echo "GlassFish Recycle was successful" >> glassfishRecycle.log
else
echo "The Glassfish Stop did not work successfully.Please see the logs 'glassfishRecycle.log'" >>glassfishRecycle.log
endif
mailx -s "This is a test for Glassfish recycle automation" xyz@yth.com < glassfishRecycle.log


Report •
Related Solutions


Ask Question