Tar file with logging and directory via parameter

Hi all,

I am fairly new to shell scripting and I am trying the following:

My shell script creates a tar file with files with the ending ~. The directory - where the files and sub directories are located - comes as a parameter when I call the script. Files that are archived will be written in a log /var/log/ttl.log and files that have been archived shall be deleted. Deleted files shall also be written in the log under /var/log/ttl.log. Files with the ending ~ in sub directories shall not be deleted. I hope this makes sense.

What I have so far:

#!/bin/bash
args="$1/"
if [ $# -eq 0 ]
   then
      echo "$(date) no parameter specified" >> /var/log/ttl.log
      exit;
else
if [ -d $1 ]
   then
      find $args -type f -name "*~" -print | xargs tar rvf /home/scripte/something.tar >> /var/log/ttl.log --remove-file

else
echo "$(date) no valid directory given" >> /var/log/ttl.log
exit;
fi
fi

This works, but the files are not deleted :confused:. Can someone point me in the right direction please?

Another thing: How would I go about deleting the files in the sub directories as well as a next step of my script?

Help is very much appreciated.

Thanks a bunch

EDIT: got it - thread closed

OK, discover all files ending with ~ in or under the current dir and put them in a tar. Log what is in the tar. Delete top level files in the archive. Log deleted files.

I usually get the file names from the tar itself, so nothing is deleted if I cannot list the tar error free. Delete list can be kept in an env var, so temp files are not needed, just pipes. First pipeline is "find ...|tar c..." archive all tilde files. Second pipeline is "dlist=`tar t ... | tee -a logfile | grep -v / `" logs all archived. Then just "delete $dlist" and "echo $dlist >>logfile". Put appropraite headings and trailers in the log, too, and time stamps from 'date'.