in Education by
I would like to get the exit code of my remote command. It's normally pretty easy, but I need to execute my command through a bastion host and I don't know take that with a easy methode. So, this is a diagram of my architecture. PC => Bastion => remote host I used this code to execute my command and check the return code: ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -At ubuntu@$ip_bastion ssh -Aq -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@$ip_server bash <<EOF { ${cmd} ; } 2>&1 | sed -e 's/^/$(colors_next exec)$region:$ip:$type${normal} /' EOF echo $? if [[ $? -ne 0 ]]; then error "Error during the command execution." exit 1 fi But, the return code is always equal 0, while my command failed (Return 255 on the final server). Thanks for your help :) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you are using bash, you can use the PIPESTATUS array variable to get the exit status of each element of the pipeline. ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -At ubuntu@$ip_bastion ssh -Aq -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ubuntu@$ip_server bash <<EOF { ${cmd} ; } 2>&1 | sed -e 's/^/$(colors_next exec)$region:$ip:$type${normal} /' exit "\${PIPESTATUS[0]}" EOF remote_exitcode=$? echo "remote_exitcode=${remote_exitcode}" if [[ ${remote_exitcode} -ne 0 ]]; then error "Error during the command execution." exit 1 fi

Related questions

0 votes
    I have the following cronjobs in my crontab: 0 22 * * 1-6 /root/sbin/mysqlbackup --conf-dir=/ ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    In shell script, How can I set 0 as default value to parameter. param2=0 ${2:-0} and ${2 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    In shell script, How can I set 0 as default value to parameter. param2=0 ${2:-0} and ${2 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    In shell script, How can I set 0 as default value to parameter. param2=0 ${2:-0} and ${2 ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    what is the difference between this two commands? sudo setfacl -R -m u:www-data:rwx -m u:yourname ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    what is the difference between this two commands? sudo setfacl -R -m u:www-data:rwx -m u:yourname ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I am trying to create a windows service. The purpose of service is to pick up urls from a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    Which of these jump statements can skip processing the remainder of the code in its body for a particular ... questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Could someone one clarify why my Eclipse (http://developer.android.com/sdk/index.html) from ADT won't ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I have a project that was build in Xcode9. Now I am updating it to Xcode10. I am using ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    i am working on a MVC project in java. For my operation I use database many times. many times my ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    I am trying to nail down free space on a remote server by querying all the drives and then looping ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I want to connect to db on EC2 from my local machine, I am not able to do and have tried everything- I ... to connect to the database Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I started Tensorflow some days back and I understand that it is a visualization tool but is there any way to ... remote Ubuntu machine? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    A _______________ is a program application which is stored on a remote-server & distributed over the Internet ... -Cyber Security:,Cyber Security-Jobs:,Cyber Security Applications...
asked Oct 31, 2021 in Education by JackTerrance
...