Unix BASH Scripting - Crontab output to file

I have a script which runs weekly on my crontab (see below) but would like to output results to file, how would I do this?

I tried including this option pointing to a txt file but didn't seem to work:

2>&1 >
#!/usr/bin/ksh
#Alert log tidy script

logDir="/bea_domains/config/AHE_CIT/logs"
tempDir="/tmp/alertLogArchive"
date=`date +%Y%m%d`
archiveDir="/bea_domains/config/AHE_CIT/logs/archive"

mkdir $tempDir

cd $logDir

find . -name "*alert.log*" -type f -mtime +30 -exec mv '{}' $tempDir \;

tar cvf - ${tempDir}/* | gzip > ${archiveDir}/alertlog_archive.${date}.tar.gz

rm -fr $tempDir

cd $archiveDir

find . -name "alertlog_archive*" -type f -mtime +60 -exec rm {} \;

Open in new window

Lico_wAsked:
Who is Participating?
 
woolmilkporcCommented:
Hi,

you could change yiur crontab entry like

* * * * * /path/to/script >/path/to/log 2>/path/to/errorlog

or you could add as the second/third lines to your script

exec 1>/path/to/log
exec 2>/path/to/errorlog

Of course you could combine both logs by using

2>&1 instead of 2>/path/to/errorlog

wmp
0
 
plshrkCommented:
The output usually is in your mail que.
Try this:  0 * * * * ~/script.sh >/dev/null 2>&1
0
 
Lico_wAuthor Commented:
Both solutions work perfectly.
0
 
woolmilkporcCommented:
The second solution will give no output at all and you won't receive any email either. Is this what you desire?

Thx for the points anyway.

wmp
0
 
TintinCommented:
Note that

cmd 2>&1 >file

will not produce the same results as

cmd >file 2>&1

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.