#!/bin/bash
LOGFILE=/var/log/backup.log 
backup_source="/home"
backup_dest="/home/sean"
date=`date '+%d-%B-%Y'`
hostname=$(hostname -s)
filename="$hostname-$date.tgz"
echo "Backing Up your Linux System"
tar cvpzf $backup_dest/$filename $backup_source
LOGFILE="log-$date.log"
log(){
    message="$@"
    echo $message
    echo $message >>$LOGFILE    
}

log "$LOGFILE"
log | tee install.log

echo "Backup finished"
echo "$LOGFILE"

hie I'm trying append teh files i have backed up into log file. All i get is a blank logfile. This what i have so far

Recommended Answers

The argument to the function log is just "log-$date.log". So only that will go to the log file. Try "ls -l (SOURCE DIRECTORY)" as the argument to the log function.

NOTE: Use the -r option to append the files into the tar archive. Using -c option will create new archive …

Jump to Post

All 2 Replies

The argument to the function log is just "log-$date.log". So only that will go to the log file. Try "ls -l (SOURCE DIRECTORY)" as the argument to the log function.

NOTE: Use the -r option to append the files into the tar archive. Using -c option will create new archive every time.

Hope it helps.

Why don't you put directly tee as piped from the tar -v command?

LOGFILE="log-$date.log"
tar cvpzf $backup_dest/$filename $backup_source | tee $LOGFILE
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.