Capture the command run in the log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Capture the command run in the log file
# 1  
Old 08-08-2006
Capture the command run in the log file

Hi ,

I have seen some log files where they have captured the command that is being executed, comments present in the scripts and the out put of the command as well, through scripts. could any one of you please let me know how do i do that?

Thanks in advance.

Cheers,
Waseem
# 2  
Old 08-08-2006
Code:
echo "yourcommand args" > log_file.txt
yourcommand args >> log_file.txt

or maybe it's running a trace and capturing output and tracing execution:
Code:
{
    set -x
    yourcommand args
    set +x
} > yourlog.txt 2>&1

# 3  
Old 08-09-2006
Oh- i never knew that, you could capture even the comments b tracing. i guess, you are right, as they are using set -vf probably thats how they are accomplishing this.


also, incase of command failures will the script teminate? like, in the below code, the file is not found so i want the script to terminate? if yes, then, how do i avoid from script terminating. for instance, i would want to ignore even if the file is not present and continue running the next commands?????

Code:
{
set -x
rm filename
rm: could not find the file
set +x

i will test it later. anyways thanks for your help!!!

Cheers,
Waseem Smilie

Last edited by ahmedwaseem2000; 08-09-2006 at 04:29 AM..
# 4  
Old 08-09-2006
No, the script will not terminate unless you want it to.
Code:
if ! rm filename
then
    exit 1
fi

# 5  
Old 08-09-2006
Hey thanks for your reply.

as i do not have the access to a unix box right now, so i will try it later.

Many Thanks,

Cheers - Waseem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor and capture the latest entry from the log file

Hi, I want to monitor a log file using tail -f command and search for a specific string on the most recent entry from the file. If the search string matches with the most recent or last line from the file, I want send an email to the people with the message. tail -f service.log|tail -n 1 ... (5 Replies)
Discussion started by: svajhala
5 Replies

2. Shell Programming and Scripting

How to capture last 15mins data logged from server.log file?

Below is Script to scan the errorlist file (errorlist file includes a list of errors) with sererv.log file (sererv.log file should contain data of recent 15mins ) but my requirement is I should get the recent logs i.e. cmd to capture only recent 15mins data logged from sererv.log file then scan... (3 Replies)
Discussion started by: manohar2013
3 Replies

3. Shell Programming and Scripting

Script to capture string in a log file

Dear all, I have a log file to be analysed. this log file contains vaiours lines of code starting with date timestamp. if my search string is exception then that resepective log statement starting from the date is required. example: 2014/10/01 16:14:44.459|>=|E|X|19202496|2832|... (5 Replies)
Discussion started by: shravee
5 Replies

4. AIX

Capture whoami log on a specific command

// AIX 6.1 TL8 Please advise on how to capture whoami log or the user and time info into a log file (i.e. /tmp/cmdcapture.log) whenever users are executing a certain command(s) so that I can keep the single log history (for all users) of who did what. The command(s) I need to monitor are a... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

5. Shell Programming and Scripting

Help using telnet to capture log file with autogenerate timestamp

Hello, I'm just joining, and looking for a solution to my problem. I have an app act as server which forward log data using telnet (server). And in my centos machine, act as a telnet client to capture the data, and an application called recorder which readd those log data and to process it then... (4 Replies)
Discussion started by: eddlinux
4 Replies

6. Shell Programming and Scripting

Capture all error message in Log file and send the Log file by email

Hi I have a requirement to write a script to capture all errors in a Logfile and send the file in email. If there is any error occurred the subject of email will be ERROR , If there are no error occurred the subject of email will be SUCCESS. So I created a Log file and put the Appropriate... (2 Replies)
Discussion started by: dgmm
2 Replies

7. Shell Programming and Scripting

capture last run log using dsjob

Hi All, Could you please let me know how to capture the WARNING or FATAL errors for the last run log using dsjob -logsum in Korn Unix Shell. Thanks in Advance, (0 Replies)
Discussion started by: HemaV
0 Replies

8. Shell Programming and Scripting

How to capture output to log file

Hi I have a script that will run multiple unix & sql commands. I want to see the output as well as capture it to a log file for further analysis. Is there an easy way to do that instead of adding "tee -a logfile" on everyline or even on the execute line (i.e. script | tee -s logfile). Thanks (1 Reply)
Discussion started by: nimo
1 Replies

9. UNIX for Dummies Questions & Answers

DOS batch file to capture routers log

Hi, Please help to write DOS /Perl script to capture router AAA logs to store in file. RADIUS: id 1, priority 1, host 59.163.6.103, auth-port 1901, acct-port 1902 State: current UP, duration 1928071s, previous duration 0s Dead: total time 2798488914s, count 0 Authen:... (0 Replies)
Discussion started by: patilanna
0 Replies

10. Shell Programming and Scripting

capture nohup log file

Hi, I am running my script using nohup, but I am not able to capture the log file for that process could naybody please help... Here is what I am doing.... nohup ./script & 1>/home/user1/log.txt but I am not able to capture the log.....Is there anyother way I can capture the log... (2 Replies)
Discussion started by: mgirinath
2 Replies
Login or Register to Ask a Question