Solved

find command check

Posted on 2008-10-27
15
295 Views
Last Modified: 2013-12-06
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 {}\;
0
Comment
Question by:linuxpig
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
15 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22818687
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 {}\;

0
 

Author Comment

by:linuxpig
ID: 22818726
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 {}\;
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22818735
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)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:linuxpig
ID: 22819539
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 22819616
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 {} \;
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 22819662
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 22819694
omarfarid: it should work in this very case, but always remember about filesnames with whitespaces.
0
 

Author Comment

by:linuxpig
ID: 22821064
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
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 22821123
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
0
 

Author Comment

by:linuxpig
ID: 22821130
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?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 22821166
It looks only at timestamp.
0
 

Author Comment

by:linuxpig
ID: 22916672
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 {} \;
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 100 total points
ID: 22916779
47 02 * * * /usr/bin/find  /home/clientid -name "access.log.*" -type f -mmin +120 exec  /usr/bin/gzip {} \;

the extra field user-to-run-as is accepted in system wide /etc/crontab only
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question