?
Solved

find command check

Posted on 2008-10-27
15
Medium Priority
?
299 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
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

764 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