If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Delete files in /tmp that are not in use

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-11-04, 10:39
bytheway5 bytheway5 is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Delete files in /tmp that are not in use

I need to delete files from the /tmp directory every night. I can need to have to script do a search and only delete files from the /tmp directory that are not currently in use. Any help would be great.


Solaris 8
Reply With Quote
  #2 (permalink)  
Old 02-11-04, 11:00
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The following code in an extract from an AIX script (/usr/sbin/skulker) that you can use.

Code:
remove_file()
{
        if [ -z "`/usr/sbin/fuser $1 2>/dev/null`" ]; then
           /usr/bin/rm -f $1
        fi
}

# get rid of all ordinary files in the /tmp directory older than 24
# hours and not accessed or modified in the past 24 hours.

/usr/bin/find /tmp -xdev -atime +1 -mtime +1 -type f -print | \
        while read FILE2REM
        do
                remove_file $FILE2REM
        done
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 02-11-04, 16:46
bytheway5 bytheway5 is offline
Registered User
 
Join Date: Feb 2004
Posts: 2
Thank you. This works great.

Quote:
Originally posted by aigles
The following code in an extract from an AIX script (/usr/sbin/skulker) that you can use.

Code:
remove_file()
{
        if [ -z "`/usr/sbin/fuser $1 2>/dev/null`" ]; then
           /usr/bin/rm -f $1
        fi
}

# get rid of all ordinary files in the /tmp directory older than 24
# hours and not accessed or modified in the past 24 hours.

/usr/bin/find /tmp -xdev -atime +1 -mtime +1 -type f -print | \
        while read FILE2REM
        do
                remove_file $FILE2REM
        done
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On