Issue in Untaring the Tar files Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue in Untaring the Tar files Script
# 1  
Old 07-16-2012
Issue in Untaring the Tar files Script

I have written a below script to untar the tar files from /tmp/tarfiles/ directory.

Code:
# cat /tmp/tarfiles/script.sh
 
#!/bin/sh
cd /tmp/tarfiles/
TFL="tar_files_list.txt"
TCF="tar_completed_list.txt"
ls -l *.tar | awk '{print $9}' > $TFL
for i in `cat $TFL`
do
 if [ -s $TCF ]
   then
    for j in `cat $TCF`
     do
        if [ "$i" = "$j" ]
           then
              echo " "
           else
             tar -xvf $i
        fi
     done
  else
     tar -xvf $i
 fi
done
cp tar_files_list.txt tar_completed_list.txt

It should not untar the files which are un tarred in previous execution. i.e. It should untar only new files.

i.e. it has to compare as below.
Code:
i - j
1 = 1
2 = 2
3 = 3
4 = 4

But it is comparing as below and untars the files which are untarred already.
Code:
i - j
1 = 1
1 = 2
1 = 3
1 = 4
2 = 1
2 = 2
2 = 3
2 = 4

and so on...


Any one pls help on this....

Last edited by Scott; 07-16-2012 at 09:08 AM.. Reason: Please use code tags
# 2  
Old 07-16-2012
Why do you do it that complicated? Can't you just move them away in another directory or rename them when they have been untarred?
# 3  
Old 07-16-2012
Code:
#!/bin/sh
cd /tmp/tarfiles
TFL="$(ls *.tar)"
TCF="tar_completed_list.txt"
touch "$TCF"
for i in $TFL; do
   if ! grep -q "$i" $TCF; then
      tar -xf $i
   fi
done
printf "%s\n" $TFL > $TCF


Last edited by xbin; 07-16-2012 at 06:49 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to tar files inside a script?

Hi , I have a file which contains few file names. I need to tar those files but am unable to do inside the script. Any help will be useful. cat /tmp/test aa.txt bb.txt cc.txt I have tried the below code but its not working. for i in `cat /tmp/test';do tar -cvf TEST.tar $i;done (9 Replies)
Discussion started by: rogerben
9 Replies

2. Shell Programming and Scripting

Backup script to split and tar files

Hi Guys, I'm very new to bash scripting. Please help me on this. I'm in need of a backup script which does the ff. 1. If a file is larger than 5GB. split it and tar the file. 2. Weekly backup file to amazon s3 using s3rsync 3. If a file is unchanged it doesn't need to copy to amazon s3 ... (4 Replies)
Discussion started by: ganitolngyundre
4 Replies

3. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

4. Shell Programming and Scripting

Need script to tar files older than 30 days

Hi all. Here's my situation: I have performance reports that run every 30 minutes saved in the format: stats_report_11251000.txt stats_report_11251030.txt stats_report_11251100.txt stats_report_11251130.txt (Obviously run at Nov 25 10 AM, 10:30 AM, 11 AM and so on...) I would... (2 Replies)
Discussion started by: jamie_collins
2 Replies

5. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

6. Shell Programming and Scripting

using tar via su in a script issue !!!

I am trying to implement the below command in my shell script su - $PROCESS -c `tar -tvf $file|tee -a $LOG/$file.log` The idea is to get the tar output on the screen and at the same time it should put the output in the log file. Problem is: 1) I donot get the output on the screen. 2)... (3 Replies)
Discussion started by: kpatel786
3 Replies

7. Shell Programming and Scripting

Script to tar up old log files

Hell All! I need help writing a script for my job. I never really wrote alot of scripts but I guess it a first time for everything. I need to write a simple script that goes out to our log file directory on our servers and tar and compress them. I need to know how to add an date time stamp to tell... (5 Replies)
Discussion started by: aojmoj
5 Replies

8. Shell Programming and Scripting

How to process the files using .tar.gz files in script

Hi, I have some file in /users/xyz directoty with .tar.gz extension. i need to find these files and if found in need to run other commands. I now the command for finding files,but how to put if condition ?please help me Thanks (3 Replies)
Discussion started by: bmkreddy
3 Replies

9. Shell Programming and Scripting

untaring multiple files

Hi, i'm pretty new to unix and shell scripting and i need to untar a load of files all with different names e.g. YAAN00.V404.T13467.tar, YAAN00.V404.T15623.tar etc with the .T* part following no particular series. I tried to untar them in a script using simply tar -xvf YAAN00.V404.T*.tar ... (3 Replies)
Discussion started by: rinceboy
3 Replies

10. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies
Login or Register to Ask a Question