Sponsored Content
Full Discussion: Redirect within ksh
Top Forums Shell Programming and Scripting Redirect within ksh Post 302247876 by fpmurphy on Thursday 16th of October 2008 02:12:57 PM
Old 10-16-2008
This is an example of one way of doing what you want to do from within a shell script. It is a modified version of a code snippet I picked up some time ago on the Internet, forget where, so apologies to the original author.

Code:
#!/usr/bin/ksh
#
#  Within a shell script set up simultaneous output
#  to both terminal and a file using a FIFO
#

# delete output file
OUTPUT=log
[[ -e $OUTPUT ]] && rm $OUTPUT

# set up redirects
exec 3>&1 4>&2
FIFO=fifo.$$
[[ -e $FIFO ]] || mkfifo $FIFO
tee $OUTPUT < $FIFO >&3 &
PID=$!
exec > $FIFO 2>&1

# rest of your shell script here i.e.
echo "STDOUT `date`"
echo "STDERR `date`" >&2
# to here

# exit tee and clean up
exec 1>&3 2>&4 3>&- 4>&-
wait $PID
rm $FIFO

exit 0

 

10 More Discussions You Might Find Interesting

1. IP Networking

Redirect

I'm sittig behind a firewall that doesn't allow ftp. I have a conection to a UNIX system, connecting throug SSH. Is it possible to redirect the ftp through the UNIX to my computer? (1 Reply)
Discussion started by: <Therapy>
1 Replies

2. UNIX for Dummies Questions & Answers

how do redirect in bind

Hello all! Does anyone know how to redirect i link to a host or alias name? Here is the example: i wank to type "Bob" in my browser and be redirected to http://192.168.54.37:7001/Bob/BobMainServlet on that perticular port. Im using Redhat 6.2 with bind 9.2.3 regards... dOzY (4 Replies)
Discussion started by: dozy
4 Replies

3. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

4. Shell Programming and Scripting

KSH problem - how do i redirect three times?

i need to output an ls command to a file but also capture any errors from that command and output them to a log file and the screen. if it's only possible to output them to a log file and not the screen then that's fine. this is what i've tried so far, but it won't populate log.txt. i've... (16 Replies)
Discussion started by: mjays
16 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

KSH Redirect to Pipe (">|") Syntax

Occasionally I see this in ksh scripts: somepgm >| someoutputfile This appears to be redirecting the output of somepgm to the file someoutputfile, and it does do so. But when you remove the pipe symbol "|" from this command, output simply goes to the screen (stdout). Why do we need the... (6 Replies)
Discussion started by: Tanuka
6 Replies

7. Shell Programming and Scripting

KSH - mailx - Redirect the undelivered mail

Hi, I need to create one KSH which will send mail to set of recipients using "mailx" command like below. mailx -s "Test mail" "test@yahoo.com, test@gmail.com" <$output.txt The recipients are in different domains (like yahoo, gmail, etc.). My requirement is, if any mail is undelivered,... (1 Reply)
Discussion started by: Matrix2682
1 Replies

8. Shell Programming and Scripting

Redirect o/p from shell

hi, I've a shell which does few manipulations on different text files. I need to divert all the output to a single file. i dont want to mention the o/p file name in command prompt (or) in every shell command. Is it possible to mention it part of the shell? Thanks (2 Replies)
Discussion started by: dvah
2 Replies

9. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

10. Shell Programming and Scripting

ksh- redirect stderr to file and then modify the file

I have the following: remsh $host -n 2>>syslog_issue_list.txt grep -i -e "EMS" -e "error" -e "warning" -e "excessive" /var/adm/syslog/syslog.log | awk /"$DATE1"/ | awk -vhost="$host" '!/remsh|telnetd/{print host "\n", $0 >> "syslog_issue_list.txt"}' I am creating a health script that has... (4 Replies)
Discussion started by: chipblah84
4 Replies
FAXQUIT(8)						      System Manager's Manual							FAXQUIT(8)

NAME
faxquit - tell a HylaFAX server to terminate SYNOPSIS
/usr/sbin/faxquit [ -q queue-dir ] [ modem ] DESCRIPTION
faxquit sends a message to a HylaFAX server process telling it to quit operation. If modem is specified, the faxgetty(8) process servicing the specified modem is notified. modem can either be the name (typically the last component of the terminal port the modem is attached to), or the full name of the associated FIFO named pipe file, e.g. ``FIFO.ttym2''. If no modem is specified, faxquit will send the request to the ``FIFO'' named pipe file causing the HylaFAX queue manager process to termi- nate. Note that server processes may not terminate immediately. In particular the faxq process will not exit until any active jobs are com- pleted; this is necessary for proper operation (faxq must wait for child processes to terminate so that it can collect their exit status and update the state of the jobs being operated on). OPTIONS
-q dir Use a spooling area other than /var/spool/hylafax. FILES
/var/spool/hylafax default spooling area /var/spool/hylafax/FIFO fifo for contacting faxq Consult hylafax-server(5) for a complete discussion of the structure and content of the spooling area. SEE ALSO
hylafax-server(5), faxq(8), faxgetty(8) October 3, 1995 FAXQUIT(8)
All times are GMT -4. The time now is 11:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy