Howto cancel I/O redirection ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Howto cancel I/O redirection ?
# 1  
Old 02-06-2013
Howto cancel I/O redirection ?

Hi

on AIX systems (6.x and 7.x) I have ksh scripts redirecting I/O, and running another script script000.ksh ie :
Code:
# my script
...
>${LOG}
>${LOGCTRL}

exec >>${LOG} 2>>${LOG}

. ${PROJECT}/.../script000.ksh

# hereafter, restore default I/O
...

Is it possible at the end of the script to restore I/O to their normal state, not feeding ${LOG} file ?
# 2  
Old 02-06-2013
Quote:
Originally Posted by Fundix
exec >>${LOG} 2>>${LOG}

... <snip> ...

Is it possible at the end of the script to restore I/O to their normal state, not feeding ${LOG} file ?
Yes. Before the redirections performed by the exec statement, save (dup) the file descriptors so that you can restore them. An example:
Code:
exec 5>&1 6>&2        # save the original stdout and stderr
exec >>${LOG} 2>&1    # redirect stdout and stderr to ${LOG}
... <do some work here> ...
exec 1>&5 2>&6        # restore the original destinations of stdout and stderr
exec 5>&- 6>&-        # close the no longer needed backup descriptors

I chose 5 and 6 for no particular reason. Naturally, if the code that does the intervening work manipulates or redirects the chosen backup descriptors, bad things could happen (including not being able to restore stdout and stderr to their initial states). Choose yours appropriately.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 3  
Old 02-07-2013
I've never had to use file descriptors in the past. Today, i've learned something very useful.
Thank You Alister, it works perfectly SmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to cancel wget download after 1%?

I am running a video download test and automating that. I wanna know how to stop a wget download session when downloads reached 1% Thanks in advance, Tamil (11 Replies)
Discussion started by: tamil.pamaran
11 Replies

2. UNIX for Dummies Questions & Answers

Cannot cancel a print

Hi Everyone, I am trying to cancel a print. I am logged on as the user of the print and when I use the command 'cancel print_job' I get the message 'print_job: not authorized' I have cancelled other prints in the queue, but this particular job in the queue cannot delete. I even logged on as... (5 Replies)
Discussion started by: Scarlet
5 Replies

3. Shell Programming and Scripting

Cancel down 2 integers

Wonderful evening to all of you! My problem has to possible starting points. Well, not really, but getting to either one is no problem at all. So i got either a string in the format of "1920x1080" or simply the integers X = 1920 and Y = 1080. When I am done, I would like to have an output... (5 Replies)
Discussion started by: jakunar
5 Replies

4. UNIX for Dummies Questions & Answers

can't cancel nohup job

Yesterday I started a nohup job called assoc.sh. It has not finished running, but I have realised a problem with my script, so wish to cancel it, modify and restart it. However, I cannot find the PID, so can't cancel it. I have searched the ps list and nothing resembles my job - how can I cancel... (13 Replies)
Discussion started by: polly_falconer
13 Replies

5. Post Here to Contact Site Administrators and Moderators

Cancel Account

I accidentally typed a wrong user name... pls delete my account so that i can create a new one.. Thanks (4 Replies)
Discussion started by: Pat_Martin
4 Replies

6. Post Here to Contact Site Administrators and Moderators

cancel account

id like to cancel my account please. thanks (5 Replies)
Discussion started by: samb057
5 Replies

7. Solaris

Cron Job... How to cancel it.

Hello, I am sort of new to cron jobs, I have a cron job running everyday that no longer needs to. How do I cancel it? (4 Replies)
Discussion started by: komputersman
4 Replies

8. UNIX for Dummies Questions & Answers

Cancel QCompile

I need help, please!!!!!!!! I have accidentally selected to compile all my programs, which will probably take forever!! How can I cancel the compiling of the programs. I see in qstatus the huge list of programs waiting to be compiled. Thanks! :eek: (1 Reply)
Discussion started by: itldp
1 Replies

9. UNIX for Advanced & Expert Users

cancel the massage

Hi all In Aix system Someone know i want to cancel the massage. if some user print something and user root deleting the job i got brodcast message " message from queueing system job number XXX has been deleteing from queue. <EOT> " I use the cancel command (1 Reply)
Discussion started by: goldfelda
1 Replies

10. UNIX for Dummies Questions & Answers

How to cancel all printjobs at once?

Hi unix-friends, I've got an RS6000 with Unix 4.3 as OS. I'm writing a script that i want to use for cancelling all print jobs at once. Does anyone have any good idea's, hints, or tips? Hope to hear from you, Erik (3 Replies)
Discussion started by: Erik Rooijmans
3 Replies
Login or Register to Ask a Question