Turn off exec 2>${_ERRORFILE} > ${_LOGFILE} feature?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Turn off exec 2>${_ERRORFILE} > ${_LOGFILE} feature?
# 1  
Old 03-04-2017
Turn off exec 2>${_ERRORFILE} > ${_LOGFILE} feature?

Hi Folks -

To make a long story short, this script is loaded into a workbench, executed via workbench user interface, and then I need to display the output on screen. However, I'm using the functions to direct stdout and stderror to their respective directories.

Is there a way to turn that off so I can leverage the cat command? Else, when I place my cat commands just prior to the exits, it doesn't work.

Here is my script:

Code:
#!/bin/bash
#::------------------------------------------------------------------------
#::-- Script Name: FDMEE_Act_Load.sh
#::  
#::-- Description: This Script Executes the FDMEE RunBatch Utility
#::                
#::-- Paramaters:  Call setenv.sh to determine the following:
#::                 1. Login
#::                 2. Password
#::                 3. Server
#::                 4. Application
#::                 5. Database
#::                 6. etc
#::      
#::-- Author:        
#::-- Date:            
#:: ------------------------------------------------------------------------
source /app/hyp_app/scripts/setenv.sh

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

echo Script Name: ${_SN}
#::-- Script Name w/o EXT: ${_SN%%.sh*} --::#

#::-- Set Log & Error Files --::#
_INTRA_PATH=${_FDMEE_LOG_DIR}
_ERROR_INTRA_PATH=${_FDMEE_ERROR_DIR}

_LOGFILE=${_INTRA_PATH}/${_DATETIMESTAMP}_${_SN%%.sh*}.log
_ERRORFILE=${_ERROR_INTRA_PATH}/${_DATETIMESTAMP}_${_SN%%.sh*}.err
    echo ${_LOGFILE}

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

#::-- Begin Script Processing --::#
echo ------------------------------------------
echo ${_SN} Starting at ${_TIME}                      
echo ------------------------------------------
echo ------------------------------------------
echo Execute FDMEE Actuals Load           
echo ------------------------------------------
 
. ${_FDMEE_UTIL_DIR}/runbatch.sh $APPID -f:${_FDMEE_APP_PSWRD} ${_FDMEE_BATCH}

if [ $? -eq 0 ]
then
    echo ------------------------------------------
    echo ${_SN%%.sh*} - Completed Successfully           
    echo ------------------------------------------
    echo ------------------------------------------
    echo Script Process Exiting Normally          
    echo ------------------------------------------
  exit 0
else
    echo ------------------------------------------
    echo ${_SN%%.sh*} - Completed Unsuccessfully           
    echo ------------------------------------------
    echo ------------------------------------------
    echo Script Process Exiting Abnormally          
    echo ------------------------------------------
  exit 1
fi

Thank you!
# 2  
Old 03-04-2017
Hi, try:
Code:
cat something > /dev/tty

# 3  
Old 03-04-2017
Hi there -

Thanks for the reply. Unfortunately, that didn't work.
# 4  
Old 03-04-2017
Hi,

The trick is to assign additional file descriptors to stdout and stderr before you re-direct them, then point them back to the additional re-directors you 'saved' earlier, so to speak.

For example:

Code:
$ cat script.sh
#!/bin/bash

exec 3>&1 4>&2 1>out 2>err
echo "This is standard output from the script"
(>&2 echo "And here is an error")
exec 1>&3 2>&4
echo "And here is standard output as normal again"
(>&2 echo "And stderr too")

$ cat out
$ cat err
$ ./script.sh
And here is standard output as normal again
And stderr too
$ cat out
This is standard output from the script
$ cat err
And here is an error
$

Hope this helps.
This User Gave Thanks to drysdalk For This Post:
# 5  
Old 03-04-2017
What did not work? What did you do?

I thought you wanted the cat command just before the exit command?

To show the principle if you execute this script
Code:
exec > logfile 2>errfile
echo some error >&2
echo some message
cat logfile > /dev/tty

The screen should display "some message"
The file logfile should contain "some message"
The file err file should contain "some error"

Does that not happen?
# 6  
Old 03-04-2017
Hi Folks -

Thanks for all your help!!

This is what did thw trick for me, thanks to drysdalk!

Code:
source /app/hyp_app/scripts/setenv.sh

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

echo Script Name: ${_SN}
#::-- Script Name w/o EXT: ${_SN%%.sh*} --::#

#::-- Set Log & Error Files --::#
_INTRA_PATH=${_FDMEE_LOG_DIR}
_ERROR_INTRA_PATH=${_FDMEE_ERROR_DIR}

_LOGFILE=${_INTRA_PATH}/${_DATETIMESTAMP}_${_SN%%.sh*}.log
_ERRORFILE=${_ERROR_INTRA_PATH}/${_DATETIMESTAMP}_${_SN%%.sh*}.err

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

exec 3>&1 4>&2 1>${_LOGFILE} 2>${_ERRORFILE}

#::-- Begin Script Processing --::#
echo ------------------------------------------
echo ${_SN} Starting at ${_TIME}                      
echo ------------------------------------------
echo ------------------------------------------
echo Execute FDMEE Actuals Load           
echo ------------------------------------------
 
. ${_FDMEE_UTIL_DIR}/runbatch.sh $APPID -f:${_FDMEE_APP_PSWRD} ${_FDMEE_BATCH}

if [ $? -eq 0 ]
then
    echo ------------------------------------------
    echo ${_SN%%.sh*} - Completed Successfully           
    echo ------------------------------------------
    echo ------------------------------------------
    echo Script Process Exiting Normally          
    echo ------------------------------------------
    exec 1>&3 2>&4
    cat ${_LOGFILE}
  exit 0
else
    echo ------------------------------------------
    echo ${_SN%%.sh*} - Completed Unsuccessfully           
    echo ------------------------------------------
    echo ------------------------------------------
    echo Script Process Exiting Abnormally          
    echo ------------------------------------------
  exit 1
fi

Thanks again!
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Just can't turn off ipv6?

I'm running a Linux OS that uses Debian as it's base. A commercial vpn is installed that uses OpenVPN. For some reason, I can't get ipv6 to tunnel properly .... and Ipleak.net shows that my location is being unmasked by ipv6. I've tried kernel commands at boot, I've tried sysctl.conf commands.... (2 Replies)
Discussion started by: benc
2 Replies

2. UNIX for Beginners Questions & Answers

Exec command with mutt - turn on & off?

Hi Folks - Quick question around the exec command again. At the end of my script, I check for specific error codes that are returned from a process I execute within the shell script. Based on the error code, I send an email. Do I need to turn off exec feature prior to send each email so... (5 Replies)
Discussion started by: SIMMS7400
5 Replies

3. 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

4. UNIX for Dummies Questions & Answers

turn off sound

how to disable anoying beep sound??? (4 Replies)
Discussion started by: nnn
4 Replies

5. UNIX for Dummies Questions & Answers

How to turn off duplex

I am using digital Unix and lpd. I have HP 4200n LaserJet TCP printer, but when I use lpr command, it always print duplex. I can turn off duplex feature at the panel of the printer, but then other Windows computer cannot print duplex. How can I set up /etc/printcap file so that it will be... (2 Replies)
Discussion started by: hiepng
2 Replies

6. SCO

BASH-like feature. is possible ?

Greetings... i was wondering if there is any shell configuration or third party application that enables the command history by pressing keyboard up arrow, like GNU/BASH does or are there an SCO compatible bash versio to download? where ? just wondering (sory my stinky english) (2 Replies)
Discussion started by: nEuRoMaNcEr
2 Replies
Login or Register to Ask a Question