Upstart script with expect scripting
Clash 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.
linux cron expect upstart shebang
add a comment |Â
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.
linux cron expect upstart shebang
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
add a comment |Â
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.
linux cron expect upstart shebang
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.
linux cron expect upstart shebang
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
add a comment |Â
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
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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