LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-15-2007, 03:58 AM   #1
Angelic_Mew
LQ Newbie
 
Registered: Nov 2007
Posts: 9

Rep: Reputation: 0
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.
 
Old 11-15-2007, 06:57 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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.
 
Old 11-15-2007, 07:20 AM   #3
Angelic_Mew
LQ Newbie
 
Registered: Nov 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 11-15-2007, 09:21 AM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
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/
 
Old 11-15-2007, 02:27 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 11-15-2007, 05:25 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,371

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
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.
 
Old 11-20-2007, 07:25 AM   #7
Angelic_Mew
LQ Newbie
 
Registered: Nov 2007
Posts: 9

Original Poster
Rep: Reputation: 0
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.
 
Old 11-20-2007, 11:25 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You are.


Cheers,
Tink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
periodic freezes AhYup Slackware 1 02-13-2005 10:14 PM
periodic network disconnections nobbie Slackware 2 01-18-2005 08:52 PM
Does Linux need periodic reformats? Tyir Linux - General 25 11-14-2003 03:48 PM
periodic freezing piccardcapt Linux - General 3 06-16-2003 08:18 AM
Periodic stalls in X Tyco Slackware 3 06-07-2003 02:25 PM


All times are GMT -5. The time now is 09:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration