Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get redirected stdout file name 4

Status
Not open for further replies.

LKBrwnDBA

MIS
Jun 16, 2003
1,866
US

Easy one for you gurus:

How can I get the file name of an redirected stdout from my executing script?

For example, I execute:

Code:
 MyScript.ksh parm1 parm2 >/path/to/redirected_out.log

I need to know the name of the redirected file "/path/to/redirected_out.log" inside MyScript.ksh [ponder]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Here's a solution that doesn't use [tt]lsof[/tt], but needs the [tt]/proc[/tt] file system...
Code:
#!/bin/ksh

STDOUT=$(ls -l /proc/$$/path/1 | sed 's/^.* //1')

print "This script's stdout is going to: ${STDOUT}"
The code works for Solaris. Change it to the following for Linux...
Code:
#!/bin/ksh

STDOUT=$(ls -l /proc/$$/[b]fd[/b]/1 | sed 's/^.* //1')

print "This script's stdout is going to: ${STDOUT}"
 

Thanks guys, I will try it out!


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top