Executing multiple child scripts - failing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Executing multiple child scripts - failing
# 8  
Old 12-08-2016
@Rudi -

Thank you so much. I have to say, that was a complete oversight on my part! I copied that exit portion in wrong.

It should be:

Code:
exit 1
fi

As far as the trap command, I've put earlier in the script. Is that correct?

@bakunin -

Thank you for that explanation. If I followed it correctly, my script should look like the following:

Code:
source /u01/app/Hyperion_Batch/Scripts/Shell/_env.sh

#::-- Set Script Name --::
_SN=${0##*/}

echo "Script Name: $_SN"
echo "Script Name without EXT: ${_SN%%.sh*}"

#::-- Set Path Variables --::
_MAINPATH=/u01/app/Hyperion_Batch/
_LOGPATH=Logs/
_ERRORPATH=Errors/

#::-- Set Log & Error subdirectory pertaining to specific process --::

_PLOGPATH=LCM_Logs/
_PERRORPATH=LCM_Errors/

#::-- Set Date and Time Variable --::
_DAY=$(date +%d)
_MONTH=$(date +%m)
_YEAR=$(date +%Y)
_DATESTAMP=${_YEAR}${_MONTH}${_DAY}
_HOUR=$(date +%H)
_MINUTE=$(date +%M)
_SECOND=$(date +%S)
_TIME=${_HOUR}${_MINUTE}
_DATETIMESTAMP=${_DATESTAMP}_${_TIME}

#::-- Establish Log and Error File Directories --::
_ARC_LF=${_MAINPATH}${_LOGPATH}${_PLOGPATH}${_YEAR}_${_MONTH}${_DAY}
_ARC_EF=${_MAINPATH}${_ERRORPATH}${_PERRORPATH}${_YEAR}_${_MONTH}${_DAY}
    mkdir -p ${_ARC_LF}
    mkdir -p ${_ARC_EF}

#::-- Prepare File Name Format --::    
_FN=${_TIME}_${_SN%%.sh*}

#::-- Establish standard out and standard error --:: 
_LF=${_ARC_LF}/${_FN}.log
_EF=${_ARC_EF}/${_FN}.err

#::-- Establish LCM Specifics --::

_EPM_SYSTEM_BIN=/u01/app/Oracle/Middleware/user_projects/epmsystem1/bin/
_IMPORTEXPORT_DIR=/u01/app/Oracle/Middleware/user_projects/epmsystem1/import_export/TVeriRep_Automation_Base/
_LCM_DIR=ESB-TVerRep


exec 2>${_EF} > ${_LF}
trap "[ -s ${_EF} ] || rm -f ${_EF} ] && rmdir ${_ARC_EF}"

#:: Begin Login Process --::
echo ----------------------------------------------------------
echo "Execute all command lines"
echo ----------------------------------------------------------

sed "s/name=\"\" password=\"\"/name=\"${LCM_USER}\" password=\"${LCM_PSWD}\"/" ${_IMPORTEXPORT_DIR}Export.xml > ${_IMPORTEXPORT_DIR}Export1.xml
rm ${_IMPORTEXPORT_DIR}Export.xml
mv ${_IMPORTEXPORT_DIR}Export1.xml ${_IMPORTEXPORT_DIR}Export.xml
sh ${_EPM_SYSTEM_BIN}Utility.sh ${_IMPORTEXPORT_DIR}Export.xml

#:: Begin Error Check --::
echo ---------------------------------------------------------                                                                                                
echo "Check for command line errors"                                         
echo ---------------------------------------------------------

if ! "s/name=\"\" password=\"\"/name=\"${LCM_USER}\" password=\"${LCM_PSWD}\"/" ${_IMPORTEXPORT_DIR}Export.xml > ${_IMPORTEXPORT_DIR}Export1.xml ; then
     echo "Error adding ${LCM_USER} and ${LCM_PSWD} to Export.xml" >2&
     exit 4
fi

if ! rm ${_IMPORTEXPORT_DIR}Export.xml > ${_IMPORTEXPORT_DIR}Export1.xml ; then
     echo "Error removing Export.xml" >2&
     exit 3
fi

if ! mv ${_IMPORTEXPORT_DIR}Export1.xml ${_IMPORTEXPORT_DIR}Export.xml ; then
     echo "Error renaming Export1.xml to Export.xml" >2&
     exit 2
fi

if ! sh ${_EPM_SYSTEM_BIN}Utility.sh ${_IMPORTEXPORT_DIR}Export.xml ; then
     echo "Error executing LCM Backup for ${_LCM_DIR} " >2&
     exit 1
fi

exit 0

Is that correct?

Thank you, both!
# 9  
Old 12-08-2016
Quote:
Originally Posted by SIMMS7400
.
.
.
As far as the trap command, I've put earlier in the script. Is that correct?
.
.
.
As long as it's early enough to catch all the events it is intended for, yes. You are missing the trap events/signals in your new script, though.
# 10  
Old 12-08-2016
Hi Rudi -

I guess im confused. Where would the trap command go then? After the command lines but before the exit portions?

Also, with the new script format, what happens when I'd only want the next command to execute only if the previous one is successful? With the new format, wont all commands execute regardless of return code?

Thanks!

Last edited by SIMMS7400; 12-08-2016 at 08:30 AM..
# 11  
Old 12-08-2016
Why not put the trap command in the script's second line right after the "shebang"? You need to get your head around it - it is not executing anything but setting a pointer to a command to be executed when the signals (in sigspec) occur any time during script execution.
And no - failing commands will make the script exit with the respective exit code.
# 12  
Old 12-08-2016
Quote:
Originally Posted by SIMMS7400
@bakunin -

Thank you for that explanation. If I followed it correctly, my script should look like the following:

Code:
[...snip...]
if ! "s/name=\"\" password=\"\"/name=\"${LCM_USER}\" password=\"${LCM_PSWD}\"/" ${_IMPORTEXPORT_DIR}Export.xml > ${_IMPORTEXPORT_DIR}Export1.xml ; then
     echo "Error adding ${LCM_USER} and ${LCM_PSWD} to Export.xml" >2&
     exit 4
fi

if ! rm ${_IMPORTEXPORT_DIR}Export.xml > ${_IMPORTEXPORT_DIR}Export1.xml ; then
     echo "Error removing Export.xml" >2&
     exit 3
fi

if ! mv ${_IMPORTEXPORT_DIR}Export1.xml ${_IMPORTEXPORT_DIR}Export.xml ; then
     echo "Error renaming Export1.xml to Export.xml" >2&
     exit 2
fi

if ! sh ${_EPM_SYSTEM_BIN}Utility.sh ${_IMPORTEXPORT_DIR}Export.xml ; then
     echo "Error executing LCM Backup for ${_LCM_DIR} " >2&
     exit 1
fi

exit 0

Is that correct?
More or less. In fact there are some syntactical errors like:
Code:
[...snip...]
if ! "s/name=\"\" password=\"\"/name=\"${LCM_USER}\" [...snip]

Where perhaps the initial command sed is missing, but i suppose that comes from copying. Otherwise you got it.

bakunin
# 13  
Old 12-08-2016
Thank you all so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Executing multiple scripts using if condition

I have an if condition. If that condition is true then one script will be run and after that I need to check another condition based on the output value of first script. i tried like below : cd lock if ; then rm exitup if ; then kb_shutdown kb_startup if ; then rm exitup if ;... (3 Replies)
Discussion started by: charanarjun
3 Replies

2. Shell Programming and Scripting

Opening Child Shell & Executing a script in the same context

Hi, Is the below possible (SHELL = tcsh)? -- I want to write an 'alias' something like this - alias set_my_work "setenv SOME_VAR;tcsh -i;source work_script.cshrc" The intention is to run this alias and enter a child shell, at the same time ensuring that the work_script.cshrc is source-ed.... (0 Replies)
Discussion started by: mishra.a.c
0 Replies

3. Solaris

ksh scripts failing with cannot execute error

Hi, All the scripts placed in /home/bin had 755 permissions. Sometimes scripts are failing with cannot execute errors. Let me describe a simple scenario. MasterScript.sh had 755 permissions. It is success most of the times. But, sometimes failing with cannot execute error. Really... (1 Reply)
Discussion started by: sureng
1 Replies

4. Shell Programming and Scripting

Script to read input and output files and child scripts

I have a directory where i have *.sas; *.pl;*.sh and *.c scripts I need to find out what are the child scripts and input output files for each script: say I have a shell script which calls a perl script and a sas script: In my first line I want I a) the parent script name; b) the... (1 Reply)
Discussion started by: ramky79
1 Replies

5. Shell Programming and Scripting

Executing all scripts in /DIR except one

First i need to find all scripts directly under /DIR that end with ".sh" extension except "noallow.sh". That can be done with: find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh" Now i want to run all the files output from the previous command. The following code: for filename in... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

6. Shell Programming and Scripting

Strange SIGINT propagation between Parent/Child sh scripts

Good day, I am trying to add signal handling capabilities to some of my scripts. Unfortunately, I am having some difficulty with the manner in which signals are propagated between parent/child processes. Consider the following example: I have the following "parent" script: #!/usr/bin/sh... (5 Replies)
Discussion started by: danie.ludick
5 Replies

7. Shell Programming and Scripting

multiple child scripts running in backgroud, how to use grep on the parent?

Hi I have a shell script A which calls another 10 shell scripts which run in background. How do i make the parent script wait for the child scripts complete, or in other words, i must be able to do a grep of parent script to find out if the child scripts are still running. My Code: ... (5 Replies)
Discussion started by: albertashish
5 Replies

8. Programming

parent not waiting until child complete executing another program through execl()

Hi, I am calling a program that greps and returns 72536 bytes of data on STDOUT, say about 7000 lines of data on STDOUT. I use pipe from the program am calling the above program. Naturally, I execute the above program (through execl() ) throught the child process and try to read the... (4 Replies)
Discussion started by: vvaidyan
4 Replies

9. UNIX for Advanced & Expert Users

executing commands in child shell

I have to execute some commands after executing one command ( cleartool setview Tagname) Problem is that I write commands in script like this. echo "test1" cleartool setview tagname echo "test2" copy file1 file2 echo "test3" but when I execute script. Output --------- test1 If I... (1 Reply)
Discussion started by: udaykishore
1 Replies

10. Shell Programming and Scripting

Error trapping in parent/child scripts

Greets all. I'm using Slackware 12.0 with the bash shell. Calling my scripts with /bin/sh... I'm building gnome-2.18.3 and I have all my build scripts ready and working but I'm calling them from a parent script which executes each child/build script in a certain order (for loop). I have "set... (6 Replies)
Discussion started by: madpenguin
6 Replies
Login or Register to Ask a Question