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.

#!/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:

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

How can I send the same output to $LOG as well with minimum code alteration ?

Did you consider the tee command?

1 Like

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.

Group your commands in parentheses or braces, and tee or redirect that group's output.

1 Like

Thank You !