Set Command to output a log of every command executed in the script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Set Command to output a log of every command executed in the script
# 1  
Old 08-22-2014
Set Command to output a log of every command executed in the script

Hi Guys,

I like to output every command executed in the script to a file.

I have tried
Code:
set -x

which does the same.

But it is not giving the logs of the child script which is being called from my script.

Is there any parameters in the Set command or someother way where i can see the log of the all the child (child of child of child of child scripts) in a single log file.

Thanks !!!!!
# 2  
Old 08-22-2014
use the below in parent script
Code:
exec >> output.log 2>&1

# 3  
Old 08-22-2014
Quote:
Originally Posted by mac4rfree
Is there any parameters in the Set command or someother way where i can see the log of the all the child (child of child of child of child scripts) in a single log file.
Alas, there is no such general setting. In fact "set -x" is not only reset for every child script but also when entering a subfunction in script. This default makes sense, because in most cases you do not want diagnostic output at all and whenever you request it explicitly (by issuing "set -x") you probably want to test only the one script (part) you set it, not everything else.

For the functionality you want i usually add the following line at a sensible place in every script:

Code:
#! /bin/ksh

[...] some introducory statements uninteresting for debugging

$chFullDebug

[...] more statements, interesting for diagnostic output

Under normal circumstances the shell variable "chFullDebug" is set to "" and the statement is silently ignored. If i need full debugging, though, i set it like this:

Code:
chFullDebug="set -xv" ; export chFullDebug

and from then on "set -xv" is issued in every script/function. because of the "export" keyword every subsequently opened environment inherits this setting.

Alternatively you could add "-xv" as option to the shebang line:

Code:
#! /bin/ksh -xv

[...] commands

If all the scripts you want to behave this way are in a certain place let a sed-script do the work for you. Put the following into a loop and feed it the list of scipt names you want to be changed:

Code:
sed '1 s/ksh/& -xv/g' /path/to/script.sh > /path/to/script.sh.debug

(Replace "ksh" with whatever shell you are using if needed.)

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script to check a command executed sucessfully or not

Hi All, I am trying to write a shell script to check if a command executed successfully or not in rhel 7 and finding the installed tomcat version. I am using below script. var4=$(find / -name "catalina.jar" ! -size 0 |egrep -v... (6 Replies)
Discussion started by: sravani25
6 Replies

2. Shell Programming and Scripting

awk command not getting executed in shell script

I am able to execute awk command from shell prompt. but the same command is not getting executed when written and run in a bash script the command from bash cmd prompt. awk '/world/{for (i=2; i<NF; i++) printf $i " "; print $NF}1' myfile >tmp$$ ; mv tmp$$ myfile file: # hello world my... (4 Replies)
Discussion started by: ashima jain
4 Replies

3. AIX

How to find the log for executed command in IBM AIX?

In Unix If we executed any command where will generate the particluar log related to command in Unix. (4 Replies)
Discussion started by: victory
4 Replies

4. UNIX for Dummies Questions & Answers

set varibale to be output of a command

Hi there! :) How to set varibale to be output of a command in csh. I was using set i="date+'%y%m%d'" but the output is date+'%y%m%d' and without quites and with a single quote the output is the same :wall: :eek: Thanks in advance (2 Replies)
Discussion started by: FUTURE_EINSTEIN
2 Replies

5. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

6. Shell Programming and Scripting

set variable to command output

I'm hoping you guys can help me out here. I've been trying different methods to try and get what IW as hoping would be a fairly simple script but has turned into a pain. Bit of background - I am writing a script to check values in certain failes to ensure they are corerct. I'm runnign this on... (2 Replies)
Discussion started by: stuc
2 Replies

7. Solaris

How to capture only some part of output when command executed??

Hi, When I execute this command prtdiag -v output sample : System clock frequency: 160 MHZ Memory size: 4GB ==================================== CPUs ==================================== E$ CPU CPU CPU Freq Size ... (4 Replies)
Discussion started by: vijaysachin
4 Replies

8. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

9. Programming

Host command NOT getting executed in Hot backup script.

Hi All, i have problem in the following Sql Script. problem is : HOST (!) command is not getting executed.pls de-bugg this HoTBackup Script...... Most urgent...! Thank You very Much !! SQL> set serveroutput on SQL> set trimspool on SQL> set line 500 SQL> set head off SQL> set feed off... (4 Replies)
Discussion started by: user__user3110
4 Replies

10. Shell Programming and Scripting

perl - why is the shell script executed before the print command?

i'm writing some simple scripts to help me learn perl. why does the print command get called after the shell script is executed? the purpose of the shell script is to simply echo to the screen "script run". which is does, but before the print command, you can clearly see the shell script is... (3 Replies)
Discussion started by: mjays
3 Replies
Login or Register to Ask a Question