Hi, I was attempting to write my first 'real' script today and had an issue with it. The script is suposed to take a directory, go through all the files in it and place the files into several 1 Gig sized tar files. It seems to divide the files up ok, but when it gets to where it runs the tar ... tar gives me errors about not being able to find the files. When i echo the tar command the script creates and then just copy the command into the console, the tar runs without a problem. Thanks for your time.
Code:
#!/bin/bash
check=$1 # directory to check
backdir=$2 # directory for backupfiles
maxsize=1000000 # size in KB of one tar
tarlist="" # will contain space delimited file names
comsize=0 # total (complete) size of all files
i=1 # file count
for files in $check/*
do
size_w=`du -s "$files"`
cursize=${size_w%*$files*} # find the size of the current file
if [ `expr $comsize + $cursize` -ge $maxsize ]
then
tarlist="$tarlist $files"
totar="$backdir/$i.tar $tarlist"
cmd="tar -cf $totar"
echo $cmd
$cmd
tarlist=""
comsize=0
i=`expr $i + 1`
else
comsize=`expr $comsize + $cursize`
tarlist="$tarlist \"$files\""
i=`expr $i + 1`
fi
done
totar="$backdir/$i.tar $tarlist"
cmd="tar -cf $totar"
echo $cmd
$cmd