Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-15-2007, 03:58 AM
|
#1
|
LQ Newbie
Registered: Nov 2007
Posts: 9
Rep:
|
Periodic cleanup of folder through Crontab with tmpwatch
Hi to everyone. This is my first post and literally my first time working on Linux.
I'm a PC technition that has to learn server administration. A+ and N+ don't cover this... lol
Anyway, I was asked to clean any file or folders in the /tmp folder that are older than 5 day's. I created a script (after hours of research...) that looks like this:
find /tmp* -mtime +5 -exec rm -rf {} \;
It works when I type it in the command view (note: I do all the work from SSH) but when I try and run it through crontab nothing happens. I tried changing the script to look like:
tmpwatch -m 120 /tmp
I added a line to crontab to make it run at 17:00 (* 17 * * * /usr/local/bin/tmpclean.sh) and after thta didn't work I tried copying the .sh into /etc/cron.d daily directory.
Yet to no avail. So now I need help. Like I said, I'm an uber nood who never touched Linux, because I didn't know how it worked and was pamperd too much by some other os, but I would really appreciate it if someone could help and also explain things as we go along.
Thanks in advanced.
|
|
|
11-15-2007, 06:57 AM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
Hi, and welcome to LQ.
First thing to consider: since you are new to Linux, most (if not all) questions you have may have already been asked and answered.
You first resource for information is www.google.com/linux for Linux related issues. That link filters out non-linux returns.
Then, please notice that there is a search function here that allows you to search these boards for posts relating to issues you may be having.
So, point you favorite browser at the link given above, and enter these search words: crontab ssh. The answer is in one of the returns on the first page of returns.
PS: If I were a manager who had a technition working for me who doesn't know how to spell techincian, or who doesn't use spellcheck, I'd have fuel for a performance review.
|
|
|
11-15-2007, 07:20 AM
|
#3
|
LQ Newbie
Registered: Nov 2007
Posts: 9
Original Poster
Rep:
|
LOL Thanx for the "greeting".
I have looked through your forums (almost) all day and did find some things that were related, however none of it helped. This is the reason why I said I tried all the way's that I listed when I posted.
Also thanks for the google linux thing. I didn't know that one. I posted here because I see that the forums were more active here than on other forums.
I have tried allot of ways that were replied to the same type of question I have, but none work and they mostly don't end with "Ok that worked, thanks".
As to your comment about my spelling. I try my hardest to type English because I'm actually Afrikaans.  I do however speak better than I type. It could also have been a slip of the fingers like...
Quote:
So, point you favorite browser
|
but still, if there is anyone who can help I'd appreciate it.

|
|
|
11-15-2007, 09:21 AM
|
#4
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
Quote:
It works when I type it in the command view (note: I do all the work from SSH) but when I try and run it through crontab nothing happens. I tried changing the script to look like:
|
Do I assume correctly that the script works from the command line if you are logged in to the system via SSH? But it doesn't work via crontab?
If so, it may be an authentication problem. Crontab has to login to the system on which you wish to run the script.
Here is a link the a post which addresses the issue of running crontab via SSH, with authentication, non-interactively. See #3.
http://www.linuxquestions.org/questi...ssword-533684/
|
|
|
11-15-2007, 02:27 PM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
The most common problem with cron is the $PATH - it differs between cron and a login
shell. Try to use the fully qualified path to find, and make that a "find /tmp "
rather than /tmp* ... chances are that there's no globbing happening, and the /tmp
will definitely cover the task at hand.
Cheers,
Tink
|
|
|
11-15-2007, 05:25 PM
|
#6
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
As per tinkster, always use full path for any cmd called from within cron, so that'd be:
/usr/bin/find
/bin/rm
also as he said, be careful with file paths as well.
|
|
|
11-20-2007, 07:25 AM
|
#7
|
LQ Newbie
Registered: Nov 2007
Posts: 9
Original Poster
Rep:
|
Oh!  So, correct me if I'm wrong here...
If I wanna use the "find" command in the crontab I must give the path to the "find" file within the folder "/usr/bin/". It won't work with a script with the "find" command in that?
Like if my script only reads
find /tmp -mtime +5 -exec rm -rf {} \;
then it won't work, but
/usr/bin/find /tmp -mtime +5 -exec rm -rf {} \;
because it goes to the find command, right?  I just want to know if I'm understanding this correctly.
|
|
|
11-20-2007, 11:25 AM
|
#8
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
You are.
Cheers,
Tink
|
|
|
All times are GMT -5. The time now is 12:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|