In a script I am writing I have it write to an error log when it doesn't complete certain tasks. I have the following set as a variable:
Code:
WRITERR="tail -n50 $LOG | grep PRODBACKUP-knik > $ERRLOG"
However what seems to be happening when I call for $WRITERR is that tail tries to tail the entire command, thus it errors out with:
Code:
tail: cannot open `|' for reading: No such file or directory
tail: cannot open `grep' for reading: No such file or directory
tail: cannot open `PRODBACKUP-knik' for reading: No such file or directory
tail: cannot open `>' for reading: No such file or directory
When I run the command inside the script but not as a variable, thus like this:
Code:
tail -n50 $LOG | grep PRODBACKUP-knik > $ERRLOG
Then it works fine, however I have the $WRITERR all over the place in the script and it just seems a lot simpler to go about it that way.
What am I doing wrong?
Below is an excerpt from the script where this is used in a real life scenario:
Code:
HOSTNAME="knik"
LOG="/var/log/backup.log"
ERRLOG="/var/log/backup-err.log"
WRITERR="tail -n50 $LOG | grep PRODBACKUP-knik > $ERRLOG"
ADMINS="emailhere"
TEMPDUMP="/usr/local/dumps/prodbackup"
if [ -f $TEMPDUMP/$HOSTNAME.1.tar.gz ];
then
echo "PRODBACKUP-$HOSTNAME: Gzipped file has been downloaded successfully!" >> $LOG
else
echo "PRODBACKUP-$HOSTNAME: No gzipped file found!" >> $LOG
echo "PRODBACKUP-$HOSTNAME: FAILURE!!" >> $LOG
$WRITERR
mail -s "Weekly Production Backup for $HOSTNAME FAILED" $ADMINS < $ERRLOG
exit 2
fi