Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Two exec commands in one shell script? Post 303030543 by SIMMS7400 on Tuesday 12th of February 2019 01:06:46 PM
Old 02-12-2019
Hi Rudi -


That worked great!!! I do have one additional follow up. I also use a trap command to remove the error file and error directory (if empty) at the end as with exec, they need to be created first.



My current trap is only working for what I have speicfic. How would I add in the a second trap statement? Do I need to do this in a function?



Code:
#!/bin/bash
#::--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#::-- Script Name: CFPBCSDDI.sh                                               --::
#::                                                                           --::
#::-- Description: Executes Cloud Artifact Snapshot Backup                    --::
#::                                                                                                                                                                                                                                                                                     --::
#::                                                                                                                                                                                                                                                                                     --::
#::                                                                                                                                                                                                                                                                                                 --::
#::--  Calls:      _env.sh                                                    --::
#::--  Called By:  N/A                                                        --::
#::                                                                                                                                                                                                                                                           --::
#::-- Parameters:  Not Applicable                                                                                                                                                                                 --::
#::                                                                                                                                                                                                                                                           --::
#::-- Author:      XXX                                                                                                             --::
#::-- Date:                   12/31/17                                                                       --::
#::                                                                                                                                                                                                                                                                                                 --::
#::--:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

#::-- Set Environment File --::#
source "$PWD/_env_DDI.sh"

#::-- Prepare File Name Format --::#
#::   _SN          = Script Name with extension
#::   ${_SN%%.sh*} = Script name without extension
#::   _FN          = File Name

_SN="${0##*/}"
_FN="${_DATESTAMP}_${_TIME}_${_SN%%.sh*}"

#::-- Set Log & Error subdirectories pertaining to the specific process --::#
_PLOGPATH="${_SN%%.sh*}_Logs/"
_PERRORPATH="${_SN%%.sh*}_Errors/"

#::-- Establish STDOUT and STDERROR repositories --::
_INTRAPATH="${_LOGPATH}${_PLOGPATH}${_YEAR}_${_MONTH}${_DAY}"
_ERRORINTRAPATH="${_ERRORPATH}${_PERRORPATH}${_YEAR}_${_MONTH}${_DAY}"

for _DIR in "${_INTRAPATH}" "${_ERRORINTRAPATH}"; do mkdir -m777 -p "${_DIR}"; done

#::-- Establish STDOUT and STDERROR files --::#
_LOGFILE="${_INTRAPATH}/${_FN}.log"
_ERRORFILE="${_ERRORINTRAPATH}/${_FN}.err"

#::-- Direct STDOUT and STDERROR to repositories --::# 
#exec 2>"${_ERRORFILE}" > "${_LOGFILE}"

_CTRLM_OUTPUT="/cfit/ctrlm/dev/links/logs"
exec > >(tee "${_CTRLM_OUTPUT}/${_FN}.log" > "${_LOGFILE}") 2> >(tee "${_CTRLM_OUTPUT}/${_FN}.err" > "${_ERRORFILE}")

#::-- Delete YYYY_MMDD error file subdirectory if empty --::
trap "[ -s ${_ERRORFILE} ] || rm -f ${_ERRORFILE} && rmdir ${_ERRORINTRAPATH}" EXIT

#::-- Additional Variable Assignment --::#  

_SNAPSHOT="Artifact Snapshot"
_TARGETPATH="${_BACKUPPATH}${_SNAPSHOT}"; mkdir -m777 -p "${_TARGETPATH}"
_CNT="0"

#::--------------------Initialize Functions--------------------------::#




Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-12-2019 at 02:15 PM.. Reason: Changed QUOTE to CODE tags.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exec. commands in python

How would i do if i'd want to execute a command in a python script or programme ? (1 Reply)
Discussion started by: J.P
1 Replies

2. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies

3. Shell Programming and Scripting

Why can't embed commands like fg or bg in a shell script ?

Hi Can someone explain in an easy way that why can't embed commands like fg or bg in a shell script ? (4 Replies)
Discussion started by: qiulang
4 Replies

4. UNIX for Dummies Questions & Answers

How to run two commands from a exec call in a c program

Hi, I have to run two commands one after another from a c program. How can i do this with exec system calls. i tried giving them as argument to execv but it is not working.please help thanks (3 Replies)
Discussion started by: suryashikha
3 Replies

5. UNIX for Dummies Questions & Answers

How to run multiple piped commands in a find -exec statement?

I can't get this to work. Running a single command works fine: find . -name "*.dat" -exec wc -l '{}' \; gives me the file name and number of lines in each .dat file in the directory. But what if I want to pipe commands, e.g. to grep something and get the number of lines with that pattern... (3 Replies)
Discussion started by: DJR
3 Replies

6. UNIX for Advanced & Expert Users

find -exec with 2 commands doesn't work (error incomplete staement)

Hi Gurues, I need to modify an existing script that uses find to search a folder, and then move its contents to a folder. What I need to do is run gzip on each file after it's moved. So, I ran this little test: Put a ls.tar file on my $HOME, mkdir tmp, and then: virtuo@tnpmprd01: find .... (3 Replies)
Discussion started by: llagos
3 Replies

7. Shell Programming and Scripting

Script Variables Inquiry, Values Okay in Standalone Exec, No-Show in Cron Exec

I have the following bash script lines in a file named test.sh. #!/bin/bash # # Write Date to cron.log # echo "Begin SSI Load $(date +%d%b%y_%T)" # # Get the latest rates file for processing. # d=$(ls -tr /rms/data/ssi | grep -v "processed" | tail -n 1) filename=$d export filename... (3 Replies)
Discussion started by: ginowms
3 Replies

8. UNIX for Dummies Questions & Answers

Using find -exec with multiple commands :(-

Hi all, Am wanting to do a ls -l of the files and do a cat of it at the same time, ideally, I am hoping that the following work but obvisouly it is not working to what I am wanting it to ... hu hu hu :wall: find . -name "BACKUP_TIMESTAMP.log" -exec "ls -l basename {} ; cat {}" \; ... (1 Reply)
Discussion started by: newbie_01
1 Replies

9. Shell Programming and Scripting

Run 2 exec commands

I have to create two instances of jBoss 5.1.0 GA. In order to do that I have to execute the following in start-jboss.sh: find . -exec /opt/novell/idm/jboss/bin/run.sh -Djboss.service.binding.set=ports-01 -c IDMProv -b 0.0.0.0 \; -exec /opt/novell/idm/jboss/bin/run.sh... (4 Replies)
Discussion started by: Joydeep Ghosh
4 Replies
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy