Upstart script with expect scripting

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Please give me advices about expect scripting combined with an upstart script.



There are 3 scripts that I am dealing with right now.



Script A) Java program



 PATH: /opt/~~/manager


Script B) Upstart script to respawn Script A



 PATH: /etc/init/xx.conf


Script C) Health check program – Pushes Script A to send a command to a process in another server and confirms the status of the connection. Run by cron.



 PATH: /opt/x~x/healthcheck.sh


What I want to do is to



1) Restart the Java process every time the server reboots or process dies
- This has been achieved with Script B.



2) Keep the connection on hold between the Java process and the process in another server by running a health check program (Script C) regularly and what it does is send a link command to the neighbor server process via telnet.



I have been failing with the above mentioned “2” and I would like to ask for advices.



Currently my script is as follows:



Script B)



description “description”

start on runlevel [2345]

stop on runlevel [!2345]

env USER=executinguser

respawn
respawn limit 2 10

script

while [ ! "`ifconfig -s | grep eth1`" ]
do
sleep 5
done

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager start |
tee -a /opt/~~.log"
end script

pre-start script

RET=`su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager status > /dev/null" || echo $?`
if [ "$RET" -eq "0" ] || [ -z "$RET" ] ; then
su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager force-stop"
fi
end script

pre-stop script

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager r force-stop"
end script



Above script works fine and the process respawns without an error.



Then to add an automatic process routing to this script, I have added this line after the main “script” section to call out an expect script.



/usr/bin/sh -f /etc/init/autolink.sh



And changed permission of the file to give an exec permission.
-rwxr-xr-x 1 root root 207 May 14 11:25 autolink.sh



/etc/init/autolink.sh



#!/usr/bin/expect -f

puts "First test"

set CMD "link routename IPaddress Port"
set HOST "localhost"

spawn telnet $HOST
expect “`^]`"
send "$CMDn"
expect "000"



and I have also tried the following




#!/usr/bin/expect -f

puts "First test"

spawn telnet IPaddress Port
expect “`^]`"
send "link routename IPaddress Port"
expect "000"



I have tried calling out the expect script with different path on Script B, and tried naming the expect script with different extension and shebang but none of them worked, in fact none of the options I have tried wouldn’t even read “puts “First test” line or reach any part of the expect script it seemed.



When I run the expect script on its own – # ./autolink.sh



It runs just fine, it receives “^]” then it doesn’t receive “000” in the end then exits after sending the link command.



I have also tired
<1> inserting the expect script into a variable in the upstart script and echo-ing the variable or
<2> getting into the expect part of the script with “expect –c “ ~~” or “/usr/bin/expect <


My question is – how should I call a piece of expect script in a shell script? And how should an expect script be written with an appropriate shebang and commands?



Thanks very much for your help in advance.







share|improve this question





















  • I see some curly quotes in your code. Make sure you using plain double quotes.
    – glenn jackman
    May 17 at 14:46










  • In expect script is not to be used? The latter script is more appropriate as an expect script?
    – AiAmAi
    May 18 at 5:13















up vote
1
down vote

favorite












Please give me advices about expect scripting combined with an upstart script.



There are 3 scripts that I am dealing with right now.



Script A) Java program



 PATH: /opt/~~/manager


Script B) Upstart script to respawn Script A



 PATH: /etc/init/xx.conf


Script C) Health check program – Pushes Script A to send a command to a process in another server and confirms the status of the connection. Run by cron.



 PATH: /opt/x~x/healthcheck.sh


What I want to do is to



1) Restart the Java process every time the server reboots or process dies
- This has been achieved with Script B.



2) Keep the connection on hold between the Java process and the process in another server by running a health check program (Script C) regularly and what it does is send a link command to the neighbor server process via telnet.



I have been failing with the above mentioned “2” and I would like to ask for advices.



Currently my script is as follows:



Script B)



description “description”

start on runlevel [2345]

stop on runlevel [!2345]

env USER=executinguser

respawn
respawn limit 2 10

script

while [ ! "`ifconfig -s | grep eth1`" ]
do
sleep 5
done

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager start |
tee -a /opt/~~.log"
end script

pre-start script

RET=`su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager status > /dev/null" || echo $?`
if [ "$RET" -eq "0" ] || [ -z "$RET" ] ; then
su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager force-stop"
fi
end script

pre-stop script

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager r force-stop"
end script



Above script works fine and the process respawns without an error.



Then to add an automatic process routing to this script, I have added this line after the main “script” section to call out an expect script.



/usr/bin/sh -f /etc/init/autolink.sh



And changed permission of the file to give an exec permission.
-rwxr-xr-x 1 root root 207 May 14 11:25 autolink.sh



/etc/init/autolink.sh



#!/usr/bin/expect -f

puts "First test"

set CMD "link routename IPaddress Port"
set HOST "localhost"

spawn telnet $HOST
expect “`^]`"
send "$CMDn"
expect "000"



and I have also tried the following




#!/usr/bin/expect -f

puts "First test"

spawn telnet IPaddress Port
expect “`^]`"
send "link routename IPaddress Port"
expect "000"



I have tried calling out the expect script with different path on Script B, and tried naming the expect script with different extension and shebang but none of them worked, in fact none of the options I have tried wouldn’t even read “puts “First test” line or reach any part of the expect script it seemed.



When I run the expect script on its own – # ./autolink.sh



It runs just fine, it receives “^]” then it doesn’t receive “000” in the end then exits after sending the link command.



I have also tired
<1> inserting the expect script into a variable in the upstart script and echo-ing the variable or
<2> getting into the expect part of the script with “expect –c “ ~~” or “/usr/bin/expect <


My question is – how should I call a piece of expect script in a shell script? And how should an expect script be written with an appropriate shebang and commands?



Thanks very much for your help in advance.







share|improve this question





















  • I see some curly quotes in your code. Make sure you using plain double quotes.
    – glenn jackman
    May 17 at 14:46










  • In expect script is not to be used? The latter script is more appropriate as an expect script?
    – AiAmAi
    May 18 at 5:13













up vote
1
down vote

favorite









up vote
1
down vote

favorite











Please give me advices about expect scripting combined with an upstart script.



There are 3 scripts that I am dealing with right now.



Script A) Java program



 PATH: /opt/~~/manager


Script B) Upstart script to respawn Script A



 PATH: /etc/init/xx.conf


Script C) Health check program – Pushes Script A to send a command to a process in another server and confirms the status of the connection. Run by cron.



 PATH: /opt/x~x/healthcheck.sh


What I want to do is to



1) Restart the Java process every time the server reboots or process dies
- This has been achieved with Script B.



2) Keep the connection on hold between the Java process and the process in another server by running a health check program (Script C) regularly and what it does is send a link command to the neighbor server process via telnet.



I have been failing with the above mentioned “2” and I would like to ask for advices.



Currently my script is as follows:



Script B)



description “description”

start on runlevel [2345]

stop on runlevel [!2345]

env USER=executinguser

respawn
respawn limit 2 10

script

while [ ! "`ifconfig -s | grep eth1`" ]
do
sleep 5
done

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager start |
tee -a /opt/~~.log"
end script

pre-start script

RET=`su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager status > /dev/null" || echo $?`
if [ "$RET" -eq "0" ] || [ -z "$RET" ] ; then
su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager force-stop"
fi
end script

pre-stop script

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager r force-stop"
end script



Above script works fine and the process respawns without an error.



Then to add an automatic process routing to this script, I have added this line after the main “script” section to call out an expect script.



/usr/bin/sh -f /etc/init/autolink.sh



And changed permission of the file to give an exec permission.
-rwxr-xr-x 1 root root 207 May 14 11:25 autolink.sh



/etc/init/autolink.sh



#!/usr/bin/expect -f

puts "First test"

set CMD "link routename IPaddress Port"
set HOST "localhost"

spawn telnet $HOST
expect “`^]`"
send "$CMDn"
expect "000"



and I have also tried the following




#!/usr/bin/expect -f

puts "First test"

spawn telnet IPaddress Port
expect “`^]`"
send "link routename IPaddress Port"
expect "000"



I have tried calling out the expect script with different path on Script B, and tried naming the expect script with different extension and shebang but none of them worked, in fact none of the options I have tried wouldn’t even read “puts “First test” line or reach any part of the expect script it seemed.



When I run the expect script on its own – # ./autolink.sh



It runs just fine, it receives “^]” then it doesn’t receive “000” in the end then exits after sending the link command.



I have also tired
<1> inserting the expect script into a variable in the upstart script and echo-ing the variable or
<2> getting into the expect part of the script with “expect –c “ ~~” or “/usr/bin/expect <


My question is – how should I call a piece of expect script in a shell script? And how should an expect script be written with an appropriate shebang and commands?



Thanks very much for your help in advance.







share|improve this question













Please give me advices about expect scripting combined with an upstart script.



There are 3 scripts that I am dealing with right now.



Script A) Java program



 PATH: /opt/~~/manager


Script B) Upstart script to respawn Script A



 PATH: /etc/init/xx.conf


Script C) Health check program – Pushes Script A to send a command to a process in another server and confirms the status of the connection. Run by cron.



 PATH: /opt/x~x/healthcheck.sh


What I want to do is to



1) Restart the Java process every time the server reboots or process dies
- This has been achieved with Script B.



2) Keep the connection on hold between the Java process and the process in another server by running a health check program (Script C) regularly and what it does is send a link command to the neighbor server process via telnet.



I have been failing with the above mentioned “2” and I would like to ask for advices.



Currently my script is as follows:



Script B)



description “description”

start on runlevel [2345]

stop on runlevel [!2345]

env USER=executinguser

respawn
respawn limit 2 10

script

while [ ! "`ifconfig -s | grep eth1`" ]
do
sleep 5
done

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager start |
tee -a /opt/~~.log"
end script

pre-start script

RET=`su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager status > /dev/null" || echo $?`
if [ "$RET" -eq "0" ] || [ -z "$RET" ] ; then
su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager force-stop"
fi
end script

pre-stop script

su - $USER -c "source /opt/~~/.bash_profile &&
/opt/~~/manager r force-stop"
end script



Above script works fine and the process respawns without an error.



Then to add an automatic process routing to this script, I have added this line after the main “script” section to call out an expect script.



/usr/bin/sh -f /etc/init/autolink.sh



And changed permission of the file to give an exec permission.
-rwxr-xr-x 1 root root 207 May 14 11:25 autolink.sh



/etc/init/autolink.sh



#!/usr/bin/expect -f

puts "First test"

set CMD "link routename IPaddress Port"
set HOST "localhost"

spawn telnet $HOST
expect “`^]`"
send "$CMDn"
expect "000"



and I have also tried the following




#!/usr/bin/expect -f

puts "First test"

spawn telnet IPaddress Port
expect “`^]`"
send "link routename IPaddress Port"
expect "000"



I have tried calling out the expect script with different path on Script B, and tried naming the expect script with different extension and shebang but none of them worked, in fact none of the options I have tried wouldn’t even read “puts “First test” line or reach any part of the expect script it seemed.



When I run the expect script on its own – # ./autolink.sh



It runs just fine, it receives “^]” then it doesn’t receive “000” in the end then exits after sending the link command.



I have also tired
<1> inserting the expect script into a variable in the upstart script and echo-ing the variable or
<2> getting into the expect part of the script with “expect –c “ ~~” or “/usr/bin/expect <


My question is – how should I call a piece of expect script in a shell script? And how should an expect script be written with an appropriate shebang and commands?



Thanks very much for your help in advance.









share|improve this question












share|improve this question




share|improve this question








edited May 17 at 12:03
























asked May 17 at 11:22









AiAmAi

63




63











  • I see some curly quotes in your code. Make sure you using plain double quotes.
    – glenn jackman
    May 17 at 14:46










  • In expect script is not to be used? The latter script is more appropriate as an expect script?
    – AiAmAi
    May 18 at 5:13

















  • I see some curly quotes in your code. Make sure you using plain double quotes.
    – glenn jackman
    May 17 at 14:46










  • In expect script is not to be used? The latter script is more appropriate as an expect script?
    – AiAmAi
    May 18 at 5:13
















I see some curly quotes in your code. Make sure you using plain double quotes.
– glenn jackman
May 17 at 14:46




I see some curly quotes in your code. Make sure you using plain double quotes.
– glenn jackman
May 17 at 14:46












In expect script is not to be used? The latter script is more appropriate as an expect script?
– AiAmAi
May 18 at 5:13





In expect script is not to be used? The latter script is more appropriate as an expect script?
– AiAmAi
May 18 at 5:13
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444345%2fupstart-script-with-expect-scripting%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f444345%2fupstart-script-with-expect-scripting%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?