Solved

find command check

Posted on 2008-10-27
15
286 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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 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…
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now