Link to home
Start Free TrialLog in
Avatar of Lico_w
Lico_w

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lico_w
Lico_w

ASKER

Both solutions work perfectly.
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
Note that

cmd 2>&1 >file

will not produce the same results as

cmd >file 2>&1