script with dates to gzip and remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script with dates to gzip and remove
# 1  
Old 08-31-2010
script with dates to gzip and remove

Good morning all!

I am new to programming and trying to learn; please be patient.

I am wanting to write a script that takes the current date and gzip 5 days or older, then remove 10 days or older.

This is the directory I want to work in; this is what it looks like
Code:
root@bigben:/var/adm/ra: ll
total 84288
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra18
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra19
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra20
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra21
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra22
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra23
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra24
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra25
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra26
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra27
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra28
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra29
-rw-r--r--   1 root       sys        3317184 Aug 31 00:11 ra30
-rw-r--r--   1 root       sys          23036 Aug 31 00:11 ra31

This is what I have:
Code:
#Go to specific location
cd /var/adm/ra
#Remove ra logs older than 10 days
find $log_dir -mtime +10 -exec rm -f {} \; 1> /dev/null 2>&1
#Gzipping ra logs older than 5 days
find $log_dir -mtime +5 -exec gzip -f {} \; 1> /dev/null 2>&1

I think my mistake is $log_dir?

Thanks Bigben
# 2  
Old 08-31-2010
add this line before find command:

Code:
log_dir=/var/adm/ra

# 3  
Old 08-31-2010
rdcwayx-

thanks! I thought it was the variable.

Does the rest of the script look like it will do what I am trying to get it to?

Ben
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove dates from file names

Hi, I'm using a shell script. I have extracted current date files to a directory1 and the date should be removed on both sides of a CSV file. FYI... I'm looking to remove the date from the file name and not inside the CSV file. Directory1 2017-07-12_gmr_tag_log_20170711.csv... (0 Replies)
Discussion started by: shivamayam
0 Replies

2. Shell Programming and Scripting

awk to combine all matching dates and remove non-matching

Using the awk below I am able to combine all the matching dates in $1, but I can not seem to remove the non-matching from the file. Thank you :). file 20161109104500.0+0000,x,5631 20161109104500.0+0000,y,2 20161109104500.0+0000,z,2 20161109104500.0+0000,a,4117... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

4. Shell Programming and Scripting

Help/How-to - simple UNIX script / gzip (beginner)

Hey all, I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this. I need to create a UNIX script that will: - scan a small number of folders and subfolders (see a similar file tree in the attachment) - - for each final folder (each of... (8 Replies)
Discussion started by: McNulty
8 Replies

5. Shell Programming and Scripting

help with a script to gzip/move files

Hi Please can you help me in writing a script to find files on a specific directory, and of extension "tap" but only of the month of september, gzip and move them to another directory. Your help will be appreciated. (4 Replies)
Discussion started by: fretagi
4 Replies

6. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

7. Shell Programming and Scripting

gzip and encrypted in a shl script

After I move the file to a directory, I need to gzip and encrypted. I never do this in a shl script, I do it from the command line and it works.. cd /home/nelnet spinel:/home/nelnet$ gpg -e 2010_11_07_05_11_xxxxxx_bills.dat.gz `/home/nelnet/.gnupg/gpg.conf' `/home/nelnet/.gnupg/gpg.conf'... (3 Replies)
Discussion started by: rechever
3 Replies

8. Shell Programming and Scripting

Need script to generate all the dates in DDMMYY format between 2 dates

Hello friends, I am looking for a script or method that can display all the dates between any 2 given dates. Input: Date 1 290109 Date 2 010209 Output: 300109 310109 Please help me. Thanks. :):confused: (2 Replies)
Discussion started by: frozensmilz
2 Replies

9. Solaris

script for Gzip thousands of file

Hi experts, I have thousands of file (data file and Gziped file) in same directory like below-- bash-2.05$ pwd /home/mmc bash-2.05$ file PP023149200709270546 TT023149200709270546: gzip compressed data - deflate method bash-2.05$ file PP027443200711242320 TT027443200711242320: ... (10 Replies)
Discussion started by: thepurple
10 Replies

10. UNIX for Dummies Questions & Answers

Remove files by dates

I've tried every way possible to remove files by date and nothing seems to work. Does anyone have an idea how to remove files by dates? Thanks in advance.... (1 Reply)
Discussion started by: dman110168
1 Replies
Login or Register to Ask a Question