Link to home
Start Free TrialLog in
Avatar of linuxpig
linuxpig

asked on

find command check

Can someone tell me whats wrong with my find command? I want to put this into cron and have it gzip the newly rotated access log  file, but its not working. So after midnight of the 25th, the log file for the 24th needs to be gzipped. exp of the name of the log file to rotate:

name: access.log.20081024

command: find /home/client -name "access.log.*" -mtime +1 -exec gzip {}\;
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

for scripts that you intend to use in crontab jobs, you need to put full path names tothe commands, set env variables, make sure that the script is executable. So,

/usr/bin/find /home/client -name "access.log.*" -mtime +1 -exec gzip {}\;

Avatar of linuxpig
linuxpig

ASKER

Thanks for the answer, i ran the command as you listed and it still didnt gzip the access log when run command line. Any ideas why?

run as:
/usr/bin/find /home/client -name "access.log.*" -mtime +1 -exec gzip {}\;
I missed the full path for gzip, so please put the full path to gzip (the dir on your system which could be /usr/bin/gzip)
Not working, when i ran this:
/usr/bin/find /home/clientid -name "access.log.*" -mtime +1 -exec /usr/bin/gzip {}\;

i got:
gzip: compressed data not written to a terminal. Use -f to force compression.
For help, type: gzip -h

So when i ran it like this:
/usr/bin/find /home/clientid -name "access.log.*" -mtime +1 -exec /usr/bin/gzip -f {}\;

it just hung and did nothing
on my system gzip is in /bin/gzip
You lack the space between {} and \;

/usr/bin/find /home/clientid -name "access.log.*" -type f -mtime +1 -exec /usr/bin/gzip {} \;
try

/usr/bin/find /home/clientid -name "access.log.*" -mtime +1 | while read file
do
    /usr/bin/gzip $file
done

you need to verify the path for gzip. Simply run

which gzip and it should return the full path
omarfarid: it should work in this very case, but always remember about filesnames with whitespaces.
Thanks guys, when i run both versions, i get the prompt back without the file being gzipped, is the mtime correct? Its like it cant find it. Heres what the file looks like in the dir im trying to gzip it in:
-rw-r--r--  1 root    root    272850 Oct 24 20:20 access.log.20081024
maybe You looking in wrong directory? Or there is no such files older than 24hours?

/usr/bin/find /home/clientid -name "access.log.*" -type f -mtime +1 # just print
Heres something else,

Nothing returns with/usr/bin/find /home/clientid -name "access.log.*" -mtime +1

But when i adjust the +1 to +2 or -1, it worked with -1 on the file dated yesterday. Any idea why? Wouldn't the date have caused this to work with +1? or does it look at the time stamp as well as the date to see if 24 hours has passed?
It looks only at timestamp.
For some reason, when im root and do crontab -e, i add the find command as a cronjob and wq! and restart crond the cron doesnt run at all. Ive done this a million times, but its not running. What am i missing? Heres the cron job, ive switched mtime to mmin
 
47 02 * * * root  /usr/bin/find  /home/clientid -name "access.log.*" -type f -mmin +120 exec  /usr/bin/gzip {} \;
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial