Sponsored Content
Top Forums Shell Programming and Scripting Redirecting command output as well as commands Post 302441021 by AncientCoder on Thursday 29th of July 2010 09:56:54 AM
Old 07-29-2010
MySQL

Quote:
awk ... [echo this part to stdout] | tee -a log.txt
I've tried using tee already -

adding 'tee -u -a exec.log' simply sends the output only to exec.log
adding 'tee -u -a exec.log 1>&3' doesn't add anything to exec.log

I need to get the output from 'awk' on the screen AND into exec.log
as well as getting the shell to send it's stderr to exec.log Smilie

Perhaps I should add that I'm testing on SCO UnixSmilie (with a plan on using on SUSE Linux once it works) so I'm really restricted as to what I can do

---------- Post updated at 08:56 AM ---------- Previous update was at 05:45 AM ----------

I've been thinking and found the answer ... not elegant but it works Smilie

create a macro that read characters and echoes them where I need them ensuring that we can't see the commands execute with the macro (could be a separate shell script I suppose to do same)

Code:
listen() {
    exec 6>&2  
    exec 2>&-
    ok=1
    while [ $ok -eq 1 ]; do
        x=`dd bs=1 count=1`
        case "$x" in
        "") ok=0; continue ;;
        esac
        echo -n $x
        echo -n $x >&3
    done
    echo "" >&3
    exec 2>&6
}

and change the 'awk' command to be

Code:
awk 'BEGIN {for(i=0;i<5;i++) {printf "\rHelloooo" i;system("sleep 1") };print "";exit }' | listen

and presto ... I get the output to original stdout AND into my 'exec.log' as I wanted

if you can improve on this please feel free to postSmilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirecting OUTPUT

Hi, I want to move the output of a command/script to a file as well as to to be displayed on stdout. Can anybody help me in this. Thanks in advace .. -Chanakya M (1 Reply)
Discussion started by: Chanakya.m
1 Replies

2. Shell Programming and Scripting

problem redirecting output of command to variable

Hi. I'm a newbie in scripting and i have this problem: i want to use the 'fuser' command on a file to tell if it's being accessed (for my purposes: still being written). I want to save the output of the command and later compare with the 'not being used' result. the script: #!/bin/bash... (2 Replies)
Discussion started by: nunovc
2 Replies

3. UNIX for Dummies Questions & Answers

redirecting commands to new xterm

hi, I need help in redirecting the commands to a new xterm. I have a executable, say my_script and another file called command.list that has several commands. my_script contents pwd xterm -e command.list I am expecting, all the commands in command.list needs to be executed in the new... (3 Replies)
Discussion started by: sujith
3 Replies

4. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

5. Shell Programming and Scripting

Merging output of two commands for a third command

I'm not sure if this is even possible but I'm hoping to avoid generating a temporary file. What I'm trying to do is append a perl command to the start of a list created by grep, then send the entire thing to mail. This is mainly to ensure that something isn't wrong when the list is blank, but it... (2 Replies)
Discussion started by: Chthonic
2 Replies

6. Shell Programming and Scripting

Reading UNIX commands from file and redirecting output to a file

Hi All I have written the following script: #!/bin/ksh while read cmdline do echo `$cmdline` pid="$cmdline" done<commands.txt =========== commands.txt contains: ps -ef | grep abc | grep xyz |awk '{print $2}; My objective is to store the o/p of the command in a variable and do... (8 Replies)
Discussion started by: rahulparo
8 Replies

7. UNIX for Dummies Questions & Answers

Redirecting the multiple commands output to single file

Hi, I am new to shell scripting and have a question. I would like to redirect the output of multple commands to single file, From what I read from the bash manpage and from some searching it seems it cannot be done within the shell except setting up a loop. Is it? I am running all clearcase... (1 Reply)
Discussion started by: saku
1 Replies

8. Shell Programming and Scripting

Redirecting command output to a file in a shell script

Hello All, I have some unique requirement. I have written a very lengthy script which calls number of resource script to execute a particular task. What I want is output of each command(called from main script and resource scripts) should go to a... (3 Replies)
Discussion started by: anand.shah
3 Replies

9. Linux

RHEL 6.3 - chage command not redirecting the output to console.

When i am issuing chage command, it reporting the output properly. But when i redirect the output, i am not getting the output in the mentioned path. chage -l root >> /tmp/chage.txt. I need to use this into the script to capture the data. I think its seems to be bug with RHEL 6.3. Same... (3 Replies)
Discussion started by: Srini.rk1983
3 Replies

10. Programming

Redirecting output to new file for command "perldoc perllocal"

Hi, I have to redirect output of the command "perldoc perllocal" to new file which contains all the perl module installed. Currently using perldoc perllocal >> mod_data This does not contain all perl modules installed locally on machine, and each character is doubled. Please... (3 Replies)
Discussion started by: asak
3 Replies
shell(1F)							   FMLI Commands							 shell(1F)

NAME
shell - run a command using shell SYNOPSIS
shell command [command] ... DESCRIPTION
The shell function concatenate its arguments, separating each by a space, and passes this string to the shell ($SHELL if set, otherwise /usr/bin/sh). EXAMPLES
Example 1 A sample output of shell command. Since the Form and Menu Language does not directly support background processing, the shell function can be used instead. `shell "build prog > /dev/null &"` If you want the user to continue to be able to interact with the application while the background job is running, the output of an exe- cutable run by shell in the background must be redirected: to a file if you want to save the output, or to /dev/null if you don't want to save it (or if there is no output), otherwise your application may appear to be hung until the background job finishes processing. shell can also be used to execute a command that has the same name as an FMLI built-in function. NOTES
The arguments to shell will be concatenate using spaces, which may or may not do what is expected. The variables set in local environments will not be expanded by the shell because "local" means "local to the current process." ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
sh(1), attributes(5) SunOS 5.11 5 Jul 1990 shell(1F)
All times are GMT -4. The time now is 06:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy