Sponsored Content
Top Forums Shell Programming and Scripting Help needed with delete script. Post 302768281 by MadeInGermany on Friday 8th of February 2013 08:41:23 AM
Old 02-08-2013
We are running the following cleantmp.sh in production environment:

Code:
#!/bin/sh

PATH=/usr/bin:/bin:/usr/sbin
export PATH

max_days=30
case $1 in
[0-9]*)
 max_days=$1
 shift
 ;;
esac

dirs_to_clean=${@:-/tmp}

owner_to_keep="root nobody"

omit=""
for i in $owner_to_keep
do
 omit="$omit ( ! -user $i )"
done

for dir in $dirs_to_clean
do
 [ -d $dir ] &&
 cd $dir &&
 find . -depth \! -type d \( -mtime +$max_days -o -mtime -0 \) \( -atime +$max_days -ctime +5 -o -ctime +$max_days -atime +5 -o -type l \) $omit -exec rm -f {} \; -o -type d -empty $omit -mtime +$max_days -exec rmdir {} \; 2>/dev/null
 sleep 1
done

exit 0
# We assume that a full backup (where atime or ctime changes) happens less often than every 5 days.
# We cd first, so there is a good chance that a too long directory path can be accessed
# if -empty is unsupported, replace it by -links 2
# A just emptied directory is deleted immediately or after another max_days
# -mtime -0 detects files with a future time stamp (were extracted from an obscure archive)

A nightly root crontab entry (crontab -e; crontab -l) could be
Code:
59 23 * * * /path/to/cleantmp.sh 10 /path/to/clean

You can add more /2ndpath/to/clean /3rdpath/to/clean ...
Nightly means, the remaining files are never older than 10+2=12 days.
For safety, frequently read files are not deleted.

Last edited by MadeInGermany; 02-08-2013 at 11:21 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

2. UNIX for Dummies Questions & Answers

Urgent help needed to delete some text without opening the file in unix

Hi To delete some text in 2 files in line1 ( not complete line) in unix without opening the files. For example: source file is like this <?xml version="1.0"... (5 Replies)
Discussion started by: pyaranoid
5 Replies

3. Shell Programming and Scripting

Need to delete the latest two files..Help needed

Suppose I have a directory called jeet and inside that directory so many files will be there.... Example: /abc/xyz/jeet $ ls -ltr total 0 -rw-r--r-- 1 oracle dba 0 Jan 13 11:36 naresh -rw-r--r-- 1 oracle dba 0 Jan 13 11:36 sreeni -rw-r--r-- 1 oracle dba ... (1 Reply)
Discussion started by: satyajit007
1 Replies

4. UNIX for Dummies Questions & Answers

Cron to delete email help needed

I would like to know if I can place a cron job (and what it might be of course) to delete all the mail in an inbox? Here are the servers specs: Operating systemLinuxService StatusClick to ViewKernel version2.6.28.9Machine Typei686Apache version2.2.11 (Unix)PERL version5.8.8Path to... (2 Replies)
Discussion started by: markmatu
2 Replies

5. Shell Programming and Scripting

Expect script help needed- script failing if router unavailable

Hey all. Sometimes I'm tasked to change some router configs for the entire network (over 3,000 Cisco routers). Most of the time its a global config parameter so its done with a loop and an IP list as its the same configuration change for all routers. This is working OK. However, sometimes an... (3 Replies)
Discussion started by: mrkz1974
3 Replies

6. UNIX for Dummies Questions & Answers

help in script needed

Hi, I am developing a script for writing out the failed jobs in file, 1)First step i need to create an empty file Status with today's date. 2)After that i need to execute the below command: dsjob -server servername -user uname -password pwd -ljobs projectname This will listout all... (5 Replies)
Discussion started by: pandeesh
5 Replies

7. Red Hat

Need Script to ZIP/SAVE & then DELETE Log file & DELETE ZIPS older than 12 months

ENVIROMENT Linux: Fedora Core release 1 (Yarrow) iPlanet: iPlanet-WebServer-Enterprise/6.0SP1 Log Path: /usr/iplanet/servers/https-company/logs I have iPlanet log rotation enabled rotating files on a daily basis. The rotated logs are NOT compressed & are taking up too much space. I... (7 Replies)
Discussion started by: zachs
7 Replies

8. Shell Programming and Scripting

Help needed for script

Hi, I have a big list like this --> 3285 3289 328D 3291 3295 3299 329D 32A1 I need to make it like --> 3285|3289|328D|3291|3295|3299|329D|32A1 Please suggest. This is Linux OS. (8 Replies)
Discussion started by: solaris_1977
8 Replies

9. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

10. Shell Programming and Scripting

Sh script help needed

Can anyone tell me what this would do in an .sh script @@ -912,10 +912,12 @@ Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: samd12
3 Replies
CYR_EXPIRE(8)						      System Manager's Manual						     CYR_EXPIRE(8)

 *

NAME
cyr_expire - expire messages and duplicate delivery database entries SYNOPSIS
cyr_expire [ -C config-file ] [ -D delete-days ] -E expire-duration [ -X expunge-days ] [ -p mailbox-prefix ] [ -v ] DESCRIPTION
Cyr_expire is used to expire messages and duplicate delivery database entries. Cyr_expire also cleanses mailboxes of partially expunged messages (when using the "delayed" expunge mode). The expiration of messages is controlled by the /vendor/cmu/cyrus-imapd/expire mailbox annotation which specifies the age (in days) of messages in the given mailbox that should be deleted. Any duplicate delivery database entries which correspond to the mailbox are also deleted at the same frequency. The value of the /vendor/cmu/cyrus-imapd/expire annotation is inherited by all children of the given mailbox, so an entire mailbox tree can be expired by seting a single annotation on the root of that tree. If a mailbox does not have a /vendor/cmu/cyrus-imapd/expire annotation set on it (or does not inherit one), then no messages are expired from the mailbox. Cyr_expire reads its configuration options out of the imapd.conf(5) file unless specified otherwise by -C. OPTIONS
-C config-file Read configuration options from config-file. -D delete-duration Remove previously deleted mailboxes older than delete-duration (when using the "delayed" delete mode). The value can be a floating point number, and may have a suffix to specify the unit of time. If no suffix, the value is number of days. Valid suffixes are d (days), h (hours), m (minutes) and s (seconds). -E expire-duration Prune the duplicate database of entries older than expire-duration. This value is only used for entries which do not have a corre- sponding /vendor/cmu/cyrus-imapd/expire mailbox annotation. Format is the same as delete-duration. -X expunge-duration Expunge previously deleted messages older than expunge-duration (when using the "delayed" expunge mode). Format is the same as delete-duration. -x Do not expunge messages even if using delayed expunge mode (reduces the IO hit considerably, allowing you to run cyr_expire fre- quently to clean up the duplicate database without overloading your server) -p mailbox-prefix Only find mailboxes starting with this prefix. e.g. "user.justgotspammedlots" -v Enable verbose output. -a Skip the annotation lookup, so all /vendor/cmu/cyrus-imapd/expire annotations are ignored entirely. It behaves as if they were not set, so only expire-days is considered for all mailboxes. FILES
/etc/imapd.conf SEE ALSO
imapd.conf(5), cyrus-master(8) CMU
Project Cyrus CYR_EXPIRE(8)
All times are GMT -4. The time now is 05:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy