Tar file with logging and directory via parameter


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Tar file with logging and directory via parameter
# 1  
Old 12-17-2012
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:
Code:
#!/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 Smilie. 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

Last edited by neg42; 12-17-2012 at 05:28 PM..
# 2  
Old 12-18-2012
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'.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

2. Shell Programming and Scripting

Help with ssh,tar and logging

Hi, I'm successfully written a script which tar a directory and ssh's it over a remote server tar cfv - $SDIR | ssh $RHOST "cat > $DDIR/backup.$BKPEXT.tar" However, Im unable to log the activity to a file. i.e for example if I do tar cfv - $SDIR | ssh $RHOST "cat >... (1 Reply)
Discussion started by: maverick_here
1 Replies

3. Solaris

HOW TO extract.tar file to specific directory..?

Hi all, In Solaris howto extract tar file to specific folder. This is what we do in Linux, but how to do the same thing in Solaris ? -tar -xzvf /tmp/etc.tar.bz -C /tmp (Will extract in /tmp dir) 3.gzip COMPRESSION AND EXTRACTION -tar -czvf /tmp/etc.tar.bz /etc -du ... (5 Replies)
Discussion started by: manalisharmabe
5 Replies

4. UNIX for Dummies Questions & Answers

SQLPLUS Password Parameter file being used when logging in

Good day to everyone. This is my first time posting and just barely above basic Unix training. I think i have search thoroughly to ensure my question hasn't already been posted. But on the off chance the answer has been posted, please be nice as I am not 100% sure I know what I am looking for. I... (1 Reply)
Discussion started by: Mrjester
1 Replies

5. Shell Programming and Scripting

Logging in unix account taking password from a parameter file

Hi All, I am writing a script where it updates a file in an unix account. To update that file i need to be logged in as that account user. say account name is ab01 and its password is passab01. What i want to do is, my script should read login id and password from a parameter file and... (4 Replies)
Discussion started by: pkbond
4 Replies

6. UNIX for Advanced & Expert Users

Solaris auditing (file access logging) for specific directory only.

Hello, We need to log the operations that specific user on Solaris 10 (SPARC) is performing on one directory and it's contents. I was able to configure solaris auditing service (auditd) and it works fine. The only problem is that auditd logs huge amount of unneeded information. We need to log... (0 Replies)
Discussion started by: +Yan
0 Replies

7. Shell Programming and Scripting

How to tar all executable file in a directory

Dear all I want to create a tar file which contains all executable files in a specific directory cd /appl/home/ file some_exe some_exe: 64-bit XCOFF executable or object module not stripped My current approach is to tar it one by one tar -cvf test.tar exefile1 tar -uvf test.tar... (2 Replies)
Discussion started by: on9west
2 Replies

8. UNIX for Dummies Questions & Answers

file restoration to new directory - tar command

hi, i face some problem which need URGENT assistance. am performing a restoration for recovery in an AIX UNIX server. when i use the tar -tvf command to view the tape contents, it gives me /ata1/mydir/myfile. i understand that how the file was backed up determine whether we could restore... (2 Replies)
Discussion started by: newbie168
2 Replies

9. Shell Programming and Scripting

TAR manipulation of file directory

I want to insert file to tar file (by tar command). The file is currently in a diffrenet directory and i want to be saved at the tar file as it was in other directory. I write the script in korn shell. How can i do it? (0 Replies)
Discussion started by: arielromi
0 Replies

10. UNIX for Advanced & Expert Users

extract a sub directory form a tar file

anyone know if it is possable to extract a subdirectory in a tar file. IE tarfile contains parent dir -sub dir A -sub dir B I want to extract sub dir B. (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question