bash redirection question
Kevin D. Clark
kclark at CetaceanNetworks.com
Fri Nov 7 16:18:04 EST 2003
Kenny Donahue writes:
> I have a c program that gathers a bunch of information then writes
> this information to a file. The c program then calls a bash script with
> the file that was created as an argument. The bash script sources the
> file and does things according to what was set in the file.
>
> Now the problem. I'd like to use the same log file for the c program
> and the shell script. Since I'm making calls in the script such as insmod,
> rm, lsmod, rmod. etc... I'd like to redirect the output from
> 1. My echos
> 2. stdio from all system calls
> 3. stderr from all system calls
> But still have everything displayed on the screen
>
> I'd like to do this without appending " | tee -a $log_file"
> to everything.
Honestly, if I were doing this on a system upon which I knew that
/bin/sh was in fact bash, I'd just modify your C program to invoke the
shell script with system(), and I'd just invoke it thusly:
system("your-script 2>&1 | tee log_file");
(error detection elided...)
You seem to be worried about appending "tee -a $log_file" to every
command in your script -- I agree, this would be slightly gross. The
solution that I have proposed avoids this.
Regards,
--kevin
--
"For we walk by faith, not by sight"
2 Corinthians 5:7
More information about the gnhlug-discuss
mailing list