How to capture the result in a subprocess
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm working with telnet memcache and I'm going to use it as example, but I suppouse it can be extended in other subjects.
In the shell the process is
telnet <ip> <port> #this start the subroutine
connected to <ip>
Escape charecter ...
flush_all #My command
OK #the response /ERROR in case it fails
quit #my command
Connection closed by foreign host.
$ echo $?
1
I want to get the OK/ERROR message, but I don't know how. I'm execute the code in a script:
#!/bin/sh
ssh user@ip '
$(
(sleep 2;
FILE="$HOME/example.log"
DATE=$(date "+%d-%m-%Y %H:%M:%S")
echo flush_all
if [ $? == 0 ]; then
RES="Success "
else
RES="Fail "
fi;
echo "$DATE - $RES" >> $FILE;
sleep 2;
echo quit;
) | telnet <ip> 11211);' 2>/dev/null
But it always return a success, even if the command is añskjdflña, and I don't know how to get the difference between OK and ERROR.
shell-script ssh
 |Â
show 1 more comment
up vote
0
down vote
favorite
I'm working with telnet memcache and I'm going to use it as example, but I suppouse it can be extended in other subjects.
In the shell the process is
telnet <ip> <port> #this start the subroutine
connected to <ip>
Escape charecter ...
flush_all #My command
OK #the response /ERROR in case it fails
quit #my command
Connection closed by foreign host.
$ echo $?
1
I want to get the OK/ERROR message, but I don't know how. I'm execute the code in a script:
#!/bin/sh
ssh user@ip '
$(
(sleep 2;
FILE="$HOME/example.log"
DATE=$(date "+%d-%m-%Y %H:%M:%S")
echo flush_all
if [ $? == 0 ]; then
RES="Success "
else
RES="Fail "
fi;
echo "$DATE - $RES" >> $FILE;
sleep 2;
echo quit;
) | telnet <ip> 11211);' 2>/dev/null
But it always return a success, even if the command is añskjdflña, and I don't know how to get the difference between OK and ERROR.
shell-script ssh
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
Does the system haveexpect
installed?
â thrig
Oct 9 '17 at 14:05
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into viassh
and that$?
in that context is the exit status of theecho flush_all
command when run on that host? That's not checking the exit status offlush_all
on the host into which you logged in viatelnet
.
â Andy Dalton
Oct 9 '17 at 18:00
 |Â
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm working with telnet memcache and I'm going to use it as example, but I suppouse it can be extended in other subjects.
In the shell the process is
telnet <ip> <port> #this start the subroutine
connected to <ip>
Escape charecter ...
flush_all #My command
OK #the response /ERROR in case it fails
quit #my command
Connection closed by foreign host.
$ echo $?
1
I want to get the OK/ERROR message, but I don't know how. I'm execute the code in a script:
#!/bin/sh
ssh user@ip '
$(
(sleep 2;
FILE="$HOME/example.log"
DATE=$(date "+%d-%m-%Y %H:%M:%S")
echo flush_all
if [ $? == 0 ]; then
RES="Success "
else
RES="Fail "
fi;
echo "$DATE - $RES" >> $FILE;
sleep 2;
echo quit;
) | telnet <ip> 11211);' 2>/dev/null
But it always return a success, even if the command is añskjdflña, and I don't know how to get the difference between OK and ERROR.
shell-script ssh
I'm working with telnet memcache and I'm going to use it as example, but I suppouse it can be extended in other subjects.
In the shell the process is
telnet <ip> <port> #this start the subroutine
connected to <ip>
Escape charecter ...
flush_all #My command
OK #the response /ERROR in case it fails
quit #my command
Connection closed by foreign host.
$ echo $?
1
I want to get the OK/ERROR message, but I don't know how. I'm execute the code in a script:
#!/bin/sh
ssh user@ip '
$(
(sleep 2;
FILE="$HOME/example.log"
DATE=$(date "+%d-%m-%Y %H:%M:%S")
echo flush_all
if [ $? == 0 ]; then
RES="Success "
else
RES="Fail "
fi;
echo "$DATE - $RES" >> $FILE;
sleep 2;
echo quit;
) | telnet <ip> 11211);' 2>/dev/null
But it always return a success, even if the command is añskjdflña, and I don't know how to get the difference between OK and ERROR.
shell-script ssh
shell-script ssh
asked Oct 9 '17 at 10:58
oootramas
115
115
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
Does the system haveexpect
installed?
â thrig
Oct 9 '17 at 14:05
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into viassh
and that$?
in that context is the exit status of theecho flush_all
command when run on that host? That's not checking the exit status offlush_all
on the host into which you logged in viatelnet
.
â Andy Dalton
Oct 9 '17 at 18:00
 |Â
show 1 more comment
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
Does the system haveexpect
installed?
â thrig
Oct 9 '17 at 14:05
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into viassh
and that$?
in that context is the exit status of theecho flush_all
command when run on that host? That's not checking the exit status offlush_all
on the host into which you logged in viatelnet
.
â Andy Dalton
Oct 9 '17 at 18:00
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
Does the system have
expect
installed?â thrig
Oct 9 '17 at 14:05
Does the system have
expect
installed?â thrig
Oct 9 '17 at 14:05
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into via
ssh
and that $?
in that context is the exit status of the echo flush_all
command when run on that host? That's not checking the exit status of flush_all
on the host into which you logged in via telnet
.â Andy Dalton
Oct 9 '17 at 18:00
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into via
ssh
and that $?
in that context is the exit status of the echo flush_all
command when run on that host? That's not checking the exit status of flush_all
on the host into which you logged in via telnet
.â Andy Dalton
Oct 9 '17 at 18:00
 |Â
show 1 more 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%2f396984%2fhow-to-capture-the-result-in-a-subprocess%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
What command are you running again?
â Raman Sailopal
Oct 9 '17 at 11:21
I want the response to 'flush_all'
â oootramas
Oct 9 '17 at 11:30
Does the system have
expect
installed?â thrig
Oct 9 '17 at 14:05
No, and I can't install it
â oootramas
Oct 9 '17 at 14:20
I suspect that this doesn't do what you think it's doing. Note that the test that sets RES runs on the host into which you logged into via
ssh
and that$?
in that context is the exit status of theecho flush_all
command when run on that host? That's not checking the exit status offlush_all
on the host into which you logged in viatelnet
.â Andy Dalton
Oct 9 '17 at 18:00