Solved

find command check

Posted on 2008-10-27
15
293 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
  • 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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…

840 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