I need help with some scripts I'm writing.
Scenario:
- Script A is executed by a scheduling process. This script takes the arguments passed to it, parses them in some way and runs script B feeding it with those arguments;
- Script B does sudo -u user ssh user@REMOTEMACHINE, runs some commands (in the remote machine) and finally runs script C (also in the remote machine). I am passing those commands using a HERE DOCUMENT. Also, I'm passing the previous arguments to this script too.
- This "flow" runs correctly and the job completes successfully.
My problems are:
- Since this "flow" is ran by a scheduling process, I need to tell it if the job completed successfully or not. I'm doing this via exit codes, so what I want is to have a chain of exit codes, returning back from the last script to the first, in case of errors. I'm not able to perform this, because exit codes works correctly for the single scripts (I tried executing them singularly and look for the exit codes), but they are not sended back to the parent script. In my opinion, the problem is that ssh is getting the exit code from the child script, which in fact ended successfully, because there was no error executing it: it's the command inside of it that gone wrong.
While the process works correctly, I still get this line:
ssh: Could not resolve hostname : Name or service not known
But actually the script completes successfully.
I hope you understand what I wrote, I can eventually post my scripts here.
Thanks
O.
EDIT:
This are the scripts. There could be some problem with variable names because I renamed it quikly to upload the files.
Since I can't upload 3 files because of my low reputation, I merged them in a single file
SCRIPT FILE
ssh ... << ... SSHREMOTECOMMANDSFOREXPORTpart, replace theif [ $? -gr 0 ]withif [ \$? -gr 0 ], so that the$?arrives as$?on the remote host via ssh, instead of being replace by0locally by your calling shell (as the last local command was probably ok). Same thing in other places, wherever you want$on the remote machine, use\$locally in most cases (to explain all the cases is complex, but in here sttrings, and inside simple quotes, use\$to avoid$being interpreted locally)