Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Turn off exec 2>${_ERRORFILE} > ${_LOGFILE} feature? Post 302992980 by drysdalk on Saturday 4th of March 2017 08:50:57 AM
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:
 

6 More Discussions You Might Find Interesting

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

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

3. UNIX for Dummies Questions & Answers

turn off sound

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

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

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

6. 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
SYSTEMD-CAT(1)							    systemd-cat 						    SYSTEMD-CAT(1)

NAME
systemd-cat - Connect a pipeline or program's output with the journal SYNOPSIS
systemd-cat [OPTIONS...] [COMMAND] [ARGUMENTS...] systemd-cat [OPTIONS...] DESCRIPTION
systemd-cat may be used to connect the standard input and output of a process to the journal, or as a filter tool in a shell pipeline to pass the output the previous pipeline element generates to the journal. If no parameter is passed, systemd-cat will write everything it reads from standard input (stdin) to the journal. If parameters are passed, they are executed as command line with standard output (stdout) and standard error output (stderr) connected to the journal, so that all it writes is stored in the journal. OPTIONS
The following options are understood: -h, --help Print a short help text and exit. --version Print a short version string and exit. -t, --identifier= Specify a short string that is used to identify the logging tool. If not specified, no identification string is written to the journal. -p, --priority= Specify the default priority level for the logged messages. Pass one of "emerg", "alert", "crit", "err", "warning", "notice", "info", "debug", or a value between 0 and 7 (corresponding to the same named levels). These priority values are the same as defined by syslog(3). Defaults to "info". Note that this simply controls the default, individual lines may be logged with different levels if they are prefixed accordingly. For details, see --level-prefix= below. --level-prefix= Controls whether lines read are parsed for syslog priority level prefixes. If enabled (the default), a line prefixed with a priority prefix such as "<5>" is logged at priority 5 ("notice"), and similar for the other priority levels. Takes a boolean argument. EXIT STATUS
On success, 0 is returned, a non-zero failure code otherwise. EXAMPLES
Example 1. Invoke a program This calls /bin/ls with standard output and error connected to the journal: # systemd-cat ls Example 2. Usage in a shell pipeline This builds a shell pipeline also invoking /bin/ls and writes the output it generates to the journal: # ls | systemd-cat Even though the two examples have very similar effects the first is preferable since only one process is running at a time, and both stdout and stderr are captured while in the second example, only stdout is captured. SEE ALSO
systemd(1), systemctl(1), logger(1) systemd 237 SYSTEMD-CAT(1)
All times are GMT -4. The time now is 06:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy