Sponsored Content
Top Forums Shell Programming and Scripting Trouble with tee command to capture script outputs Post 302288213 by cfajohnson on Monday 16th of February 2009 05:52:59 PM
Old 02-16-2009
Quote:
Originally Posted by muthubharadwaj
Code:
function GetInput
{
    print -n "Input"
    read input
    export INPUT=$input
}


When posting non-standard scripts, you should indicate which shell they are for.

Even better is to use standard syntax:

Code:
GetInput()
{
    printf "Input: "
    read INPUT
}

Quote:
Code:
export COMMAND="GetInput"
 
$COMMAND
echo "$INPUT"
 
$COMMAND | tee -a Log.log
echo "$INPUT"

The first one without "tee" works fine. echo "$INPUT" displays the values I type in for input. The second one always shows $INPUT as empty string. Why?[/code]

Where have you output the value of $INPUT? Not in $COMMAND, which is what you are redirecting.
Quote:
[code] Is there any other way to execute a shell function and capture its log output and at the same time display its output on the stdout device too without impacting its actual behavior? As you can see here, although the fucntion exports the variable INPUT, it is not available when the function call returns to the calling script code.

export does nothing there; export makes variables visible to child processes, not parent processes.

You are executing $COMMAND in a pipeline, and all elements of a pipeline (all but the last in ksh) are executed in a subshell.

Code:
GetInput()
{
    printf "Input: "
    read INPUT
}
COMMAND="GetInput"

$COMMAND
printf "%s\n" "$INPUT" | tee -a Log.log

 

10 More Discussions You Might Find Interesting

1. Cybersecurity

What command or script to capture a system snapshot?

Some background on what I am trying to accomplish - Accreditation/Certification for DoD (Unix/Linux) system: I am trying to improve the process for capturing key system information in preparation for performing a formal security review of a Unix or Linux system. This is in addition to the SRR... (1 Reply)
Discussion started by: SecureMe
1 Replies

2. UNIX and Linux Applications

Tee with pipe command.

cat work.txt M|324324|32424|3431 M|324324|32424|3431 N|324324|32426|3432 N|324324|32424|3434 M|324324|32424|3435 cat work.txt | tee $( grep '^M' > m.txt ) | $( grep '^N' > n.txt ) cehpny00:/home01/sr38632 $ cat m.txt M|324324|32424|3431 M|324324|32424|3431 M|324324|32424|3435 ... (2 Replies)
Discussion started by: rsampathy
2 Replies

3. Shell Programming and Scripting

create outputs from other command outputs

hi friends, The code: i=1 while do filename=`/usr/bin/ls -l| awk '{ print $9}'` echo $filename>>summary.csv #Gives the name of the file stored at column 9 count=`wc -l $filename | awk '{print $1}'` echo $count>>summary.csv #Gives just the count of lines of file "filename" i=`expr... (1 Reply)
Discussion started by: rajsharma
1 Replies

4. Shell Programming and Scripting

tee + more command

script1: #!/bin/ksh more test.txt script2: calling the script1 #!/bin/ksh /tmp/script1.sh 2>&1 | tee tee.log where test.txt contains ~1200 lines. When I execute the script2 the more command does not print pagewise it goes to the end of the line, when I remove the tee command it... (4 Replies)
Discussion started by: prasad111
4 Replies

5. UNIX for Advanced & Expert Users

Equivalents of tee command to find exit status of command

Hi, Want to log the output of command & check the exit status to find whether it succeeded or failed. > ls abc ls: abc: No such file or directory > echo $? 1 > ls abc 2>&1 | tee log ls: abc: No such file or directory > echo $? 0 Tee commands changes my exit status to be always... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

6. Shell Programming and Scripting

Capture IP and command type in linux script

hi guys, is there any way to capture the ip address of users who log-in to linux then capture the command executed together with the time and date? example output 192.1.1.1 : ls -ltr Aug 6 16:38:40thanks in advance. (2 Replies)
Discussion started by: d3xt3r
2 Replies

7. UNIX for Dummies Questions & Answers

Problem using tee to capture activity - nothing happens

Hi, I'm sure this is real simple but in the looking I've done I haven't seen it addressed (or didn't realize it). I've started up a PuTTY connection to our UNIX box and started screen and script - no problems. Then I typed "tee teeKH18.txt" expecting it to start tee and dump all activity into... (2 Replies)
Discussion started by: Mike Welch
2 Replies

8. Shell Programming and Scripting

Help with tee command

In the current directory , I have seven files . But when I use the following command , it lists eight files ( 7 files + file_list.xtx) ls -1 | tee file_list.xtx | while read line; do echo $line ; done Does the tee command create the file_list.xtx file first and then executes the ls -1... (1 Reply)
Discussion started by: kumarjt
1 Replies

9. Shell Programming and Scripting

Question about tee command

I have the following script as shown below where I cat a file and then also tee the output to a file as I have to email the execution of the process to users at the end of the script: cat incoming.dat | tee -a execution.log if then echo "Issue with incoming.dat file, file not... (5 Replies)
Discussion started by: calredd
5 Replies

10. Shell Programming and Scripting

Need command to capture word from shell script and send email

Hello Experts, Greeting to all of you. I have a requirement, that we have a shell script status.sh that check the status of server and server status shows as status.sh Enterprise Server - Running Admin Server - Shutdown Requirement is like whenever the output shows shutdown it should... (2 Replies)
Discussion started by: aks_1902
2 Replies
MSGEXEC(1)								GNU								MSGEXEC(1)

NAME
msgexec - process translations of message catalog SYNOPSIS
msgexec [OPTION] COMMAND [COMMAND-OPTION] DESCRIPTION
Applies a command to all translations of a translation catalog. The COMMAND can be any program that reads a translation from standard input. It is invoked once for each translation. Its output becomes msgexec's output. msgexec's return code is the maximum return code across all invocations. A special builtin command called '0' outputs the translation, followed by a null byte. The output of "msgexec 0" is suitable as input for "xargs -0". Mandatory arguments to long options are mandatory for short options too. Input file location: -i, --input=INPUTFILE input PO file -D, --directory=DIRECTORY add DIRECTORY to list for input files search If no input file is given or if it is -, standard input is read. Informative output: -h, --help display this help and exit -V, --version output version information and exit AUTHOR
Written by Bruno Haible. REPORTING BUGS
Report bugs to <bug-gnu-gettext@gnu.org>. COPYRIGHT
Copyright (C) 2001-2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for msgexec is maintained as a Texinfo manual. If the info and msgexec programs are properly installed at your site, the command info msgexec should give you access to the complete manual. GNU gettext 0.11.4 July 2002 MSGEXEC(1)
All times are GMT -4. The time now is 07:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy