ksh - get stdout name as variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh - get stdout name as variable
# 1  
Old 07-12-2005
ksh - get stdout name as variable

Writing a ksh script. If someone starts a process with:
test.ksh > date.log

How can I grab 'date.log' name as a variable in test.ksh?

I need to get the 'date.log' name (not the contents) as a variable...without entering something like 'test.ksh date.log > date.log'
# 2  
Old 07-12-2005
I guess I don't understand fully..

The redirection "name" is known only to the calling shell. test.ksh doesn't know about it at all. You will have to use either lsof or fuser to find out who has what file open.
Even then, I don't see any easy answer.

My real question is: if you were able to get it, what would you do with it?
# 3  
Old 07-13-2005
Reason: test.ksh calls many other ksh files, that outputs their own condition codes. I need to be able to go through the log and look for bad condition codes that the called ksh files put out.

I'm not really looking for a stderr, since the ksh scripts put their own errors out.

I tried lsof, but since I'm not an admin, can't mess with the bin. I'll look into the fuser idea.
# 4  
Old 07-15-2005
OK...nothing yet.

How about getting the stdout content as a variable...so I can hit it like that, or a way of copying during the process?
# 5  
Old 07-15-2005
the script/program doesn't have access to the name of the file you are redirecting its output to. I suppose you can pass the file as a parameter to the script and then redirect all output to the passed in filename manually in the script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Escaping a variable in ksh

I am trying to echo a variable exactly to a script- echo "${var1} ${var2} >> output.output Gives me a blank file. I would like output.output to basically say: ${var1} ${var2} I think I need to use a special escape character for variables. Am I right in assuming that, and is it the... (8 Replies)
Discussion started by: jeffs42885
8 Replies

2. Shell Programming and Scripting

How do I store stdout in a variable?

These seems ridiculously simple but I can't get it to work. Using korn shell and I want to pass in a flag to tell my echo statements to either write to the screen for debugging or a file if not. So I have something like: if ; then logout=&1 else logout='logfile.out' fi Then... (2 Replies)
Discussion started by: DJR
2 Replies

3. Shell Programming and Scripting

Variable to command to Variable Question KSH

Hello, First post for Newbie as I am stumped. I need to get certain elements for a specific PID from the ps command. I am attempting to pass the value for the PID I want to retrieve the information for as a variable. When the following is run without using a variable, setting a specific PID,... (3 Replies)
Discussion started by: Coyote270WSM
3 Replies

4. Shell Programming and Scripting

Redirecting stdout to variable while printing it

Hi everybody, I am trying to do the thing you see in the title, and I can't simply do a=$(svn up) echo $a because the program (svn) gives output on lots of lines and in the variable the output is stored on only one line (resulting in a horribly formatted text). Any tips? Thanks,... (2 Replies)
Discussion started by: ocirne94
2 Replies

5. UNIX for Dummies Questions & Answers

Question on using a variable in KSH

Hi all, The below command tries to copy ".tgz" instead of "hello_test.tgz" -- It seems as if the underscore gets in the way. I tried with different ways of using quotes, with no luck, unfortunately...it's probably very simple, but may I ask how this would be done: How would the below be... (3 Replies)
Discussion started by: chatguy
3 Replies

6. Shell Programming and Scripting

variable substitution in ksh

Hi I have a variable BIT1 which holds some value. Is there a way to retrieve the value of this variable indirectly via another variable, lets say SUBSET_BIT_NUM=1, so the call will look something like this: sundev1 $ echo ${BIT${SUBSET_BIT_NUM}} ksh: ${BIT${SUBSET_BIT_NUM}}: bad substitution ... (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Shell Programming and Scripting

Creating an Array in KSH from output (stdout)

Using Cygwin PDksh - But also have tested it on Linux with same results ---- I have a script that invokes a program/script and returns a string of data (1234 "12 34 56" 6789) and using "set -A" inserting it into an array. script code snipit >> get_array=$(php... (2 Replies)
Discussion started by: carlos25
2 Replies

8. Programming

stdout to a variable?

Hi, I need to set stdout to go to a String variable, has anyone got any ideas? (6 Replies)
Discussion started by: cb.mark
6 Replies

9. Shell Programming and Scripting

ksh: A part of variable A's name is inside of variable B, how to update A?

This is what I tried: vara=${varb}_count (( vara += 1 )) Thanks for help (4 Replies)
Discussion started by: pa3be
4 Replies

10. Shell Programming and Scripting

Using a variable list in ksh while

Hey all, been so long since I've done any KSH scriptting, I've forgotten exact sytax. 2 things, 1) I need to dot in an environment file that is a list of server names 2) I need to loop through though server names in a while loop, or until loop. Here's roughly what I have and trying to hammer out... (2 Replies)
Discussion started by: jpeery
2 Replies
Login or Register to Ask a Question