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]

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This topic is now closed to further replies.