How to log the output of a linux script


Recommended Posts

Ok, So I have a script and I want to output whatever it puts on the screen to a log file, I know this is really simple and I've googled and got some bits but I am unsure as to where in the script I should put them.

Any help would be appreciated.


#!/bin/bash
#
# Data copy script for training product data refresh
# 25/10/12
#
# Data copy.
echo "__________________________________________________________________"
echo Training system update STARTED `date`
echo TIMECHECK started Refreshing server product data on stuff `date`
scp -Cr /snapshot/data/stuff/PROD.FILE server:/data/stuff
scp -Cr /snapshot/data/stuff/PROD.FILE server:/data/stuff
scp -Cr /snapshot/data/stuff/STOCK.FILE server:/data/stuff
echo TIMECHECK completed server product update `date`
ssh server chmod -R 777 /data
echo "__________________________________________________________________"
~
[/CODE]

you can usee tee

for example

ls -al | tee blah.txt

this would display ls-al output on the screen but also echo it to the blah.txt too

what of the above do you want logged?

This script will be run manually but I need any output it shows on the screen to be output to a log also.

This is what I have been suggested I do.


echo Tar file created as $ZIPFILENAME >> $LOGFILE
[/CODE]

Is this the best way to have it logged?

This to see the output and log the result to a file.

$ update-client > my.log[/CODE]

[CODE]update-client 2>&1 | tee my.log[/CODE]

2>&1 redirects standard error to standard output, and tee sends its standard input to standard output and the file.

  On 25/10/2012 at 12:30, Farstrider said:
This to see the output and log the result to a file.
$ update-client > my.log[/CODE]

[CODE]update-client 2>&1 | tee my.log[/CODE]

2>&1 redirects standard error to standard output, and tee sends its standard input to standard output and the file.

Command not found in the log using update-client

This topic is now closed to further replies.