The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cp files (>5 Mb size) from one directory to another skcontact UNIX for Dummies Questions & Answers 6 06-12-2008 08:39 AM
searching files inside directory kylethesir UNIX for Dummies Questions & Answers 4 06-06-2008 02:44 AM
How to see directory and the files inside it. shaan_dmp UNIX for Advanced & Expert Users 4 12-17-2007 05:48 AM
How to delete Directory and inside files using Find command bmkreddy SUN Solaris 3 07-10-2007 03:35 PM
How to check if 3 files have same size in directory oggle Shell Programming and Scripting 5 02-16-2005 12:51 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-27-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
files of size 0 need to be deleted inside a directory

Hiiii,

I have written a script which takes backup of some log files.
let say the backuplocation is ---

/abc/backuplocation

-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3619.log
-rw-r----- 1 webmut2 spgroup 1551 Jan 25 07:13 ansrpt3619.log

after taking the backup i have to delete the files and then touch the files so that it create the file but with size 0 this is required in the script.

suppose the location of the files that need to backed up is---

/namish/logs
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt23994.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3601.log
-rw-r--r-- 1 webmut2 spgroup 0 Jan 27 02:41 ansrpt3619.log


My script is working fine for all these but a problem is coming ie when i am touchng the files they are still under the directory /namish/logs,when again i ran the script,my script is picking these files(files with size 0) also and taking the backup.I do not want this because this time the size of the file will be 0.

My script should delete the files from the backuplocation whose size is 0.

The script is -----

Code:
l) BackupLocation="$OPTARG"
                if [[ $BackupLocation != *backup ]]; then
                        echo "Appending backup subdirectories"
                        BackupLocation=$BackupLocation/backup
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        if [[ $? != 0 ]];then
                        echo "First Create The Directory And Then Take backup"
                        fi
                        cd $FileLocation
                        pwd
                        cp -R $FilesToDelete $BackupLocation
                        list=$(ls *log*)
                        for files in $list
                        do
                         echo $files >namish1
                          rm -f $files
                          touch $files
                        done
                else
                        mkdir -p $BackupLocation >/dev/null 2>&1
                        cp -R $FilesToDelete $BackupLocation
                        for files in $list
                        do
                          rm -$files
                          touch $files
                        done
                if [[ ! -d $BackupLocation ]]; then
                echo "Unable to make backup directory: $BackupLocation"
                        if [[ $IsCronJob -eq 1 ]]; then
                          SendMiddleTierCleanMail "Middletierclean error message" $mt_clean_errfile
                        fi
                        return $E_INT_MISSING_DIR
                fi
                fi
                l_flag=Y
                Llcron=l
                ;;

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0