bash - capture exit code from a script flow -
need help scripts i'm writing. scenario:
script a executed scheduling process. script takes arguments passed it, parses them in way , runs script b feeding arguments; script b sudo -u user ssh user@remotemachine, runs commands (in remote machine) , runs script c (also in remote machine). passing commands using here document. also, i'm passing previous arguments script too. this "flow" runs correctly , job completes successfully.my problems are:
since "flow" ran scheduling process, need tell if job completed or not. i'm doing via exit codes, want have chain of exit codes, returning lastly script first, in case of errors. i'm not able perform this, because exit codes works correctly single scripts (i tried executing them singularly , exit codes), not sended parent script. in opinion, problem ssh getting exit code kid script, in fact ended successfully, because there no error executing it: it's command within of gone wrong.while process works correctly, still line:
ssh: not resolve hostname : name or service not known
but script completes successfully.
i hope understand wrote, can post scripts here.
thanks
o.
edit: scripts. there problem variable names because renamed quikly upload files. since can't upload 3 files because of low reputation, merged them in single file script file
i managed solve problem. followed olivier's advice , used escape char create variable expanded remote machine. implemented different exit codes based on error occured. @ last, modified first script follows, after launching sudo -u sec script:
exitcodeofthesecondscript=$? if [ $exitcodeofthesecondscript = 0 ] echo "" echo "export job took $seconds seconds." echo "" exit 0 else exit $exitcodeofthesecondscript fi this way able exit main script maintaining exit code provided sec script. in fact, found problem process worked well, in case of errors, fact giving more commands after sec script fail (the echo command enough) provided other exit codes overwrited 1 wanted.
thanks !
bash ssh
No comments:
Post a Comment