Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a script that runs (this works fine).

I'd like to produce logfiles from its output and still show it on screen. I have this command that creates three files from this blog:

((./fk.sh 2>&1 1>&3 | tee errors.log) 3>&1 1>&2 | tee output.log) 2>&1 | tee final.log

This does exactly what I want it to.

My only issue is that I create files in my script and copy them somewhere, and I'd like to copy these logfiles there too, which I can't do whilst this script is running. I also wanted to make it easier for any user to run my script, so I created another script to run this script. According to this post (see last post) I can put a . before the script name and I can use variables assigned in my called script from the first script if I use them in the first.

It doesn't seem to work though and I can't figure out why or find alternative methods.

Can anyone help?

share|improve this question
    
You could define an environment variable that points to the directory you want, then let the script and the logs write there. Additionally, maybe wrap the line you're currently using into another script. –  slhck Jun 21 '11 at 12:10
    
I am assigning var OUTPUT in first script, but when set in called script first script only sees original value... –  neildeadman Jun 21 '11 at 13:27
add comment

2 Answers 2

up vote 0 down vote accepted

Please read the solution presented in the following link:
logging blocks of code to log files in bash @ stackoverflow.com

share|improve this answer
add comment

I've discovered that by using exec I can achieve what I wanted with out the need for a second script, like so:

#!/bin/bash
exec 1>&2-
cmd1
cmd2

Thought it worth posting in case anyone happens upon this question!

share|improve this answer
    
This isn't the exact line I used, as I am still working on it... –  neildeadman Jun 28 '11 at 8:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.