How to take output to log file aswell?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to take output to log file aswell?
# 1  
Old 07-15-2015
How to take output to log file aswell?

Hi guys,

A part of my script involves checking for the md5sum of a file.

When I run the script, it displays me the output but I want the same output to be written to a log file aswell.

Code:
#!/bin/bash

LOG=/tmp/deploy.log

MD5SUM_ADP=`md5sum /opt/code/ADPWebApp.war | awk '{print $1}'`
echo "md5sum of /opt/code/ADPWebApp.war is $MD5SUM_ADP"

Execution of the code is:

Code:
md5sum of /opt/code/ADPWebApp.war is fb0c1baea6750e2fcab0d52722eb37c8

How can I send the same output to $LOG as well with minimum code alteration ?
# 2  
Old 07-15-2015
Did you consider the tee command?
This User Gave Thanks to RudiC For This Post:
# 3  
Old 07-15-2015
That does work but only if I have one statement.

I have to check multiple md5sum and I want to add other commands that I am running to my $LOG file.
# 4  
Old 07-15-2015
Group your commands in parentheses or braces, and tee or redirect that group's output.
This User Gave Thanks to RudiC For This Post:
# 5  
Old 07-15-2015
Thank You !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Function output to log file

Hi I have a shell script that does a whole bunch of things. For the sake of simplicity, assume it runs commands one two and three. What i ultimately need is the ability to display the output of the entire script on the screen as well as capture the output in a file. When I try to do it in the... (3 Replies)
Discussion started by: rch
3 Replies

2. Shell Programming and Scripting

Displaying log file pattern output in tabular form output

Hi All, I have result log file which looks like this (below): from the content need to consolidate the result and put it in tabular form 1). Intercomponents Checking Passed: All Server are passed. ====================================================================== 2). OS version Checking... (9 Replies)
Discussion started by: Optimus81
9 Replies

3. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

4. Shell Programming and Scripting

To log binary file output to a txt file

Hi, I wrote a small script whose function is to execute the postemsg provided if the threshold breaches. I want to log this postemsg messages to a log file. But I am not able to do. Can someone throw some light on how to log the output of this. I am pasting a snippet of that code. ... (2 Replies)
Discussion started by: dbashyam
2 Replies

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

6. UNIX for Dummies Questions & Answers

Any way to grep a string in directories and return the result with diskusage aswell?

What Im basically trying to do is this: I have a small script that can grep any parameter entered into a search string, then print to the screen the name of each file the parameter appears in as well as the file path, ie the directory. The code Im using just for this is.... Directory... (3 Replies)
Discussion started by: Eddeh
3 Replies

7. UNIX for Dummies Questions & Answers

Redirection of output to a log file

Apologies for the trivial nature of this question but I cannot seem to get a simple re direct to a log file to work Step 1 touch log.txt at -f batch.sh now >> log.txt I am trying to get the batch.sh contents into the log file Manny Thanks (8 Replies)
Discussion started by: JohnCrump
8 Replies

8. Shell Programming and Scripting

Putting screen output in a log file

I want to output screen messages to a logfile when executing an automated script. I have tried the script and command to do this but with no luck. Thanks, Nicole (5 Replies)
Discussion started by: nsutti
5 Replies

9. HP-UX

SQL statement output to Log file-How?

Hi all, I need to bring the message to log file.Teradat/Hp-Ux script: ----- ### Update Log Table bteq <<- EOC .run file ${SRC_DATA}/logon.txt .run file ${SRC_DATA}/dbstagebteq.txt .set format off .set foldline off all .set sidetitles off ... (1 Reply)
Discussion started by: vsubbu1000
1 Replies

10. Shell Programming and Scripting

redirect output to log file

hello all, I'm invoking the program generate-report using backticks from my perl program and redirecting the output to the log file sge-stderr.log. But when i check the process using ps command it is spawing two processes where the below code is parent process and the program generate-report as... (2 Replies)
Discussion started by: kalyanraj
2 Replies
Login or Register to Ask a Question