LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Archive Files that are not already .gz and not today (https://www.linuxquestions.org/questions/linux-newbie-8/archive-files-that-are-not-already-gz-and-not-today-4175489279/)

contra04 12-27-2013 04:02 AM

Archive Files that are not already .gz and not today
 
Morning people, I am trying to use the script sxample on the syslog-ng webpage to rotate and zip my logs.

I am using:
/usr/bin/find /var/log/cisco ! -name "*.gz" -type f ! -path "*`/bin/date +%Y/%m/%d`*" -exec /usr/bin/gzip {} \;

But it doesnt seem to ignore today's date?

When I run:

/usr/bin/find /var/log/cisco ! -name "*.gz" -type f ! -path "*`/bin/date +%Y/%m/%d`*"

It correctly "!"'s doesn't not find the gzip files, but it still finds todays date?

I fixed this about a year ago, but for the life of me cannot remember how I did it.

Any help would be greatly appreciated

druuna 12-27-2013 04:31 AM

Quote:

Originally Posted by contra04 (Post 5087525)
Morning people, I am trying to use the script sxample on the syslog-ng webpage to rotate and zip my logs.

I am using:
/usr/bin/find /var/log/cisco ! -name "*.gz" -type f ! -path "*`/bin/date +%Y/%m/%d`*" -exec /usr/bin/gzip {} \;

But it doesnt seem to ignore today's date?

When I run:

/usr/bin/find /var/log/cisco ! -name "*.gz" -type f ! -path "*`/bin/date +%Y/%m/%d`*"

What is the bold part supposed to do in your opinion?

The date part results in 2013/12/27, are there any sub-directories that contain that string?

I guessing you want to use -mtime and possibly -daystart:
Code:

/usr/bin/find /var/log/cisco -type f ! -name "*.gz" -daystart -mtime +1 -exec /usr/bin/gzip {} \;
- Find Files By Access, Modification Date / Time Under Linux or UNIX
- A Unix/Linux “find” Command Tutorial

contra04 12-27-2013 07:18 AM

Ahh yes your right - the filenames are /deivename/devicename%date%

so this works:

#!/bin/bash

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/etc/syslog-ng/
find /var/log/cisco ! -name "*.gz" -type f ! -name "*`date +%Y%m%d`*" -exec gzip -f {} \;

as I removed the / / / from the date seems to work !

Thanks


All times are GMT -5. The time now is 10:23 PM.