Execution Output of a shell script into a file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Output of a shell script into a file.
# 1  
Old 05-10-2010
Execution Output of a shell script into a file.

Hi Experts,

I have a script called test.sh. I am trying to execute it with sh -x test.sh. Where i can find sequence of steps executed one by one. Now i want to these executions to be captured in a file.

i.e sh -x test.sh > output.txt

the above one is notworking.

can anyone help me regarding this.

Regards
Naree
# 2  
Old 05-10-2010
Try this:

Code:
sh -x test.sh > output.txt 2>&1

# 3  
Old 05-10-2010
use >& instead of >
# 4  
Old 05-10-2010
Quote:
Originally Posted by itkamaraj
use >& instead of >
Just to add that the above syntax is not standard:

Code:
$ sh -x test.sh >& output.txt
ksh: >&output.txt : illegal file descriptor name

It's supported by bash , zsh and (t)csh.
# 5  
Old 05-10-2010
Quote:
Originally Posted by radoulov
Just to add that the above syntax is not standard:

Code:
$ sh -x test.sh >& output.txt
ksh: >&output.txt : illegal file descriptor name

It's supported by bash and zsh.


i used -x inside the shell script

Code:
kamaraj@kamaraj-laptop:~/Desktop/testing$ head sample.sh
#!/bin/sh -x
cat sample.txt | awk ' /./ {print $1}' | sort | uniq > output.txt

for i in `cat output.txt`;do 
    tot=0;
    num=`grep $i sample.txt|awk '{print$2}'`; 
        for j in $num;do 
            tot=`expr $j + $tot`;
        done;
    echo "$i --> $tot"; 
kamaraj@kamaraj-laptop:~/Desktop/testing$ ./sample.sh >& shell_output
kamaraj@kamaraj-laptop:~/Desktop/testing$ head shell_output 
+ cat sample.txt
+ awk  /./ {print $1}
+ sort
+ uniq
+ cat output.txt
+ tot=0
+ grep kamaraj sample.txt
+ awk {print$2}
+ num=34
35

# 6  
Old 05-10-2010
Quote:
Originally Posted by itkamaraj
i used -x inside the shell script
[...]
I'm just saying that it's not standard.

It works with some shells.
# 7  
Old 05-10-2010
Thanks experts. It really worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. UNIX for Advanced & Expert Users

Graphical Display Of Script Execution & Output

Hello All i have a KSH script which basically takes attribute name as input argument and searches whole Netezza appliance and prints information of where that column is used (Table/Views) etc. Problem with this approach business users have to raise SUDO access request, Install Putty, run through... (1 Reply)
Discussion started by: Ariean
1 Replies

3. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

4. Programming

How to redirect the output of a shell script to a file?

hi, i have a html form which call a perl program, this perl program calls a shell script. <html> <head> <title>demo</title> </head> <body> <form name="frm1" action="/cgi-bin/perl_script.pl" method="post"> <input type="text" name="fname"> ... (1 Reply)
Discussion started by: Little
1 Replies

5. Shell Programming and Scripting

Shell Script - File Input/Output in C

This is part of my code: for in_file in $1/*.in # list of all .in files in working directory. do $c_file < $in_file > "$tempFile.out" if diff "$tempFile.out" $out_file >/dev/null 2>&1 ; then ... (6 Replies)
Discussion started by: spider-man
6 Replies

6. Shell Programming and Scripting

output from remote server during execution of a script

How to see the output from remote server during execution of a script ? I am executing a script (ls) from machine 1 but the o/p should be displayed in machine 2. Can I achieve this ? Example:- Machine 1:- # ls Machine 2:- (console) file1 file2 file 3 dir1 dir2 (0 Replies)
Discussion started by: frintocf
0 Replies

7. 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

8. Shell Programming and Scripting

getting garbage in the output file of shell script

Hi, I wrote one shell script and I am calling 1 sql script inside shell script. When I am running the shell script, I am getting actual data as well as garbage data in the output file. Why the garbage is there in the log file. Please help if anybody having any ides. Script: ------- ... (2 Replies)
Discussion started by: vsachan
2 Replies

9. Shell Programming and Scripting

getting garbage in the output file of shell script

Hi Everyone, The problem is that I am getting messages other than the script in the current log file. Ideally the script should contain only the messages that are redirected to the log file. How to remove these unwanted data from the log file. Please help if you have any idea how to remove the... (0 Replies)
Discussion started by: vsachan
0 Replies

10. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies
Login or Register to Ask a Question