I have a Bourne Shell script that is normally run as a background job and redirects it's output to a file internally (using exec >>); I use "set -x" to capture each command which provides me with a nice shell execution log if it all goes to pieces.
I now also need to be able to also run this as an interactive script whilst still keeping the "execution log" concept but have the output from certain commands also printed on the user terminal so they know what's going on during the long sections whilst keeping them in the log as well.
The following Sample Script shows on screen the output from msg() and the output from awk;
'user.log' is fine as a printable logfile;
'exec.log' shows everything BUT the output from awk
QUESTION (finally) - how can I get the output from awk to show on the original script stdout (ie user screen) AND also into exec.log
Sample Script:
Any advice/script fragments would be appreciated
Last edited by Scott; 07-29-2010 at 07:34 AM..
Reason: Please use code tags
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
Perhaps I should add that I'm testing on SCO Unix (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
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)
and change the 'awk' command to be
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 post
I'm using awk here as an example; the program I actually need to use is wodim writing to data a DVD and it takes about 15 minutes; all the time it is interactively outputting status messages that I need the user to see so they won't think it's all gone horribly wrong
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)