Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    2

    Unanswered: 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

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    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.

  3. #3
    Join Date
    Feb 2004
    Posts
    2
    Thank you. This works great.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •