Help with Output Redirection of a Unix Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with Output Redirection of a Unix Shell Script
# 1  
Old 04-28-2010
Question Help with Output Redirection of a Unix Shell Script

Hi Guys,

I have a script for which the stdout and stderr should be redirected to a log file, they should not be printed on the screen. Could you please let me know the procedure to redirect the output of the script to a log file. Thanks in advance.

--- Aditya
# 2  
Old 04-28-2010
MySQL

Code:
 
> logfile.txt 2>&1

# 3  
Old 04-28-2010
Question

Quote:
Originally Posted by ygemici
Code:
 
> logfile.txt 2>&1

Thanks.....
Do i need to add this at the end of the input ??
What is the 2>&1 ??
# 4  
Old 04-28-2010
MySQL

For exa ;
2 --> stderr
1--> stdoutput

we both of them forward to logfile.txt

Code:
/usr/local/bin/yourscript.sh > logfile.txt 2>&1

first stderror to yourlogfile and then stderror forward to stdout..so stderror and stdout forward to logfile.txt ..
# 5  
Old 04-28-2010
Question

Quote:
Originally Posted by ygemici
For exa ;
2 --> stderr
1--> stdoutput

we both of them forward to logfile.txt

Code:
/usr/local/bin/yourscript.sh > logfile.txt 2>&1

first stderror to yourlogfile and then stderror forward to stdout..so stderror and stdout forward to logfile.txt ..
Thank you so much....

---------- Post updated at 04:38 PM ---------- Previous update was at 03:00 PM ----------

Quote:
Originally Posted by ygemici
For exa ;
2 --> stderr
1--> stdoutput

we both of them forward to logfile.txt

Code:
/usr/local/bin/yourscript.sh > logfile.txt 2>&1

first stderror to yourlogfile and then stderror forward to stdout..so stderror and stdout forward to logfile.txt ..
What if input has changing parameters everytime (inputs parameters to script changes everytime), then how can we redirect output to log file ?? Do we have to specify everytime to redirect the output ??
Ex : ./sample.sh 23 > logfile.txt 2>&1 (1st time)
./sample.sh 46 > logfile.txt 2>&1 (2nd time)
In this case, do we need to specify this everytime we execute this script or can we fix it once & for all ??
# 6  
Old 04-28-2010
MySQL

Quote:
Originally Posted by chaditya
Thank you so much....

---------- Post updated at 04:38 PM ---------- Previous update was at 03:00 PM ----------



What if input has changing parameters everytime (inputs parameters to script changes everytime), then how can we redirect output to log file ?? Do we have to specify everytime to redirect the output ??
Ex : ./sample.sh 23 > logfile.txt 2>&1 (1st time)
./sample.sh 46 > logfile.txt 2>&1 (2nd time)
In this case, do we need to specify this everytime we execute this script or can we fix it once & for all ??
Then try this
Code:
./sample.sh 23 &> logfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX shell script to format output report

i am new to unix shell scripting, could someone please help me. i was asked to develop a unix script and requirement of the script is as follows: 1. In source directory, if any new files are being dropped by external system then an email should be sent out with a message saying "files are... (3 Replies)
Discussion started by: crefi1545
3 Replies

2. Shell Programming and Scripting

How to echo output of a UNIX command (like ls -l ) using shell script.?

How do i echo the output of a unix command using shell script??? Like: echo /etc/ ls -l (2 Replies)
Discussion started by: sunny2802
2 Replies

3. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

4. Shell Programming and Scripting

Command output redirection in script not working

I need to count the number of lines in a .txt file and put it in a variable. I am using the following code #!/bin/bash count = $(wc -l "some file.txt" | awk '{print$1}') echo $count It is giving the following error. line3: count: command not foundWhat am I doing wrong here? :confused: (7 Replies)
Discussion started by: haritha.gorijav
7 Replies

5. Shell Programming and Scripting

Shell script output redirection question

OS : AIX 6.1 Shell : Korn in the url https://forums.oracle.com/forums/thread.jspa?threadID=361463&tstart=0 I came across a crontab entry example 00 23 * * 1,3,5 <complete shell script path> 1> <log file> 2>&1 From googling , I gathered that 0 - stdin 1 - stdout 2 - stderr I... (5 Replies)
Discussion started by: polavan
5 Replies

6. Shell Programming and Scripting

Read input and output redirection filename within a script

Hello everyone, My requirement is that within a script I need to construct the command line exactly that it was invoked with. For example : sh a.sh arg1 arg2 arg3 < input.txt > output.txt Now within a.sh, I construct a file which has these contents " sh a.sh arg1 arg2 arg3 < input.txt >... (8 Replies)
Discussion started by: hedonist12
8 Replies

7. Shell Programming and Scripting

Redirection output

Hi there I have a script that runs but it outputs everything onto the screen instead of a file. I've tried using the > outputfile.txt however all it does is dump the output to the screen and creates an outputfile.txt but doesn't put anything in that file. Any help would be appreciated ... (6 Replies)
Discussion started by: kma07
6 Replies

8. Shell Programming and Scripting

Unix shell output redirection help

Hi all, Actually i need to know whether there is any way to redirect the output of shell operations into any file without pipe . Actually my problem is , i run some command & its result is displayed on shell after some calculations on shell, so if i redirect its output to file, it is not... (5 Replies)
Discussion started by: sarbjit
5 Replies

9. UNIX for Advanced & Expert Users

Unix Shell Script with output to CSV File

Hi, I have a unix shell script that is outputting results from an SQL query to a *.csv file, using utl_file.put_line. The resulting file is then sent out via e-mail as a mail attachment. The issue I have is that when the mailed attachment is opened in Excel the first column is shown as... (1 Reply)
Discussion started by: heather.morton@
1 Replies

10. Shell Programming and Scripting

Asking about shell script input output redirection

Hi, Can anyone please tell me what these lines do? ls >& outfile ls outfile 2>&1 Thanks. (1 Reply)
Discussion started by: trivektor
1 Replies
Login or Register to Ask a Question