Go to page | Previous  1 2 3 4 5  Next
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 3:09 am 
   
On 2009-10-30, Moe Trin wrote:
Quote:
On Fri, 30 Oct 2009, in the Usenet newsgroup alt.os.linux.mandriva, in article
hce2ts$adn$1@news.eternal-september.org>, Eric wrote:

Warren wrote:

I have confirmed with testing that this command does it:

find /home/user/vtigercrm_bak/* -mtime +2 -delete

Do you want to start the search at /home/user/vtigercrm_bak or in any
sub-directories of /home/user/vtigercrm_bak/ ?

your find cmd should be (for completeness):
find /home/user/vtigercrm_bak/ -name "*" -type f -mtime +2 -delete

The -name option isn't needed. 'find' will find all files, so the
'-name [anything] is redundent unless you are trying to avoid finding
files that begin with a dot.

-name '*' matches dot files, too, so it accomplishes nothing.

--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
ProBash Programming: Scripting the GNU/Linux Shell, 2009, Apress


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 4:35 am 
On 2009-10-30, Warren wrote:
Quote:
On Oct 30, 2:09?pm, "Chris F.A. Johnson" wrote:
? ?-name '*' matches dot files, too, so it accomplishes nothing.

Corrected; thank you.

Next problem: I can't get it to run at the time desired. The now
corrected job runs as desired from the command line (as root, "/etc/
cron.daily/backup.cron"). It is saved as 755, owner root. I used
webmin to set the daily jobs to run at 3:00 pm (1500 hrs), and
confirmed this in /etc/crontab:

$ cat /etc/crontab | grep cron.daily
0 15 * * * root nice -n 19 run-parts --report /etc/cron.daily

But 3 pm came and went with nothing done. What am I doing wrong?

Don't use the unnecessarily complicated cron-daily and its cohorts.
Leave that for system cron jobs. Put your crontab file in
/var/spool/cron

Create the file ~/crontab and install it with:

crontab ~/crontab


--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 8:07 am 
On 2009-10-31, Warren wrote:
Quote:
On Oct 30, 3:35?pm, "Chris F.A. Johnson" wrote:
? ?Don't use the unnecessarily complicated cron-daily and its cohorts.
? ?Leave that for system cron jobs. Put your crontab file in
? ?/var/spool/cron

? ?Create the file ~/crontab and install it with:

crontab ~/crontab

Let me make sure I've got this straight:

1. This job has to run as root, so I create the file /root/
crontab_daily, the contents of which is (lets say):

#!/bin/sh
# Remove vtiger backups older than 2 days
find /home/jorge/vtigercrm_bak/ -type f -mtime +2 -delete

2. I use the "crontab" command as root. I've read the manpage and I'm
not getting it. What do I do? I am sorely tempted to simply add the
line "0 15 * * * root nice -n 19 run-parts --report /root/
crontab_daily" to the already existing file /var/spool/cron/root, but
man crontab informs me that this file is not meant to be edited
directly.

# cat /root/crontab_daily
#!/bin/sh
# Remove vtiger backups older than 2 days
find /home/jorge/vtigercrm_bak/ -type f -mtime +2 -delete

# cat /root/crontab
0 15 * * * nice -n 19 /root/crontab_daily

# crontab /root/crontab

--
Chris F.A. Johnson, author |
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 8:14 am 
On Fri, 30 Oct 2009 14:13:40 -0700 (PDT), Warren wrote:
Quote:
On Oct 30, 2:09 pm, "Chris F.A. Johnson" wrote:
-name '*' matches dot files, too, so it accomplishes nothing.

Corrected; thank you.

Next problem: I can't get it to run at the time desired.

Not to cut your cron job submission/execution learning experience short, but
have you considered putting the backup deletion code in
the script creating the backups. :)

Quote:
$ cat /etc/crontab | grep cron.daily

Sorry if someone already pointed this out.
Do keep in mind when using cat and grep, you can use grep directly. Example:

$ grep cron.daily /etc/crontab
02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 9:23 am 
Warren wrote:
Quote:
On Oct 30, 3:35 pm, "Chris F.A. Johnson" wrote:
Don't use the unnecessarily complicated cron-daily and its cohorts.
Leave that for system cron jobs. Put your crontab file in
/var/spool/cron

Create the file ~/crontab and install it with:

crontab ~/crontab

Let me make sure I've got this straight:

1. This job has to run as root, so I create the file /root/
crontab_daily, the contents of which is (lets say):

#!/bin/sh
# Remove vtiger backups older than 2 days
find /home/jorge/vtigercrm_bak/ -type f -mtime +2 -delete

2. I use the "crontab" command as root. I've read the manpage and I'm
not getting it. What do I do? I am sorely tempted to simply add the
line "0 15 * * * root nice -n 19 run-parts --report /root/
crontab_daily" to the already existing file /var/spool/cron/root, but
man crontab informs me that this file is not meant to be edited
directly.
Well, what I would do is

open a console and su - to root
runs this cmd: crontab -e
and add this line to it (it may be the first line in a blank file
if so, thats ok, just paste it in there and save it)
0 15 * * * find /home/jorge/vtigercrm_bak/ -type f -mtime +2 -delete
save it and you're done
I dont mess with /etc/cron.daily or copying files to /var/spool/cron
Eric


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 9:31 am 
On Fri, 30 Oct 2009 19:07:27 -0600, Chris F.A. Johnson
wrote:

Quote:
# cat /root/crontab_daily
#!/bin/sh
# Remove vtiger backups older than 2 days
find /home/jorge/vtigercrm_bak/ -type f -mtime +2 -delete

# cat /root/crontab
0 15 * * * nice -n 19 /root/crontab_daily

# crontab /root/crontab

I'll give this a try when I'm back at the computer in question; thanks.

Your point is taken that I should leave the system cron for system
cronjobs. But I am curious why what I was doing didn't work.


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 9:59 am 
On Fri, 30 Oct 2009 22:31:48 -0400, Warren Post wrote:

Quote:
Your point is taken that I should leave the system cron for system
cronjobs. But I am curious why what I was doing didn't work.

Is the cron daemon running?

$ ps -A|grep crond

Regdards, Dave Hodgins

--
Change nomail.afraid.org to ody.ca to reply by email.
(nomail.afraid.org has been set up specifically for
use in usenet. Feel free to use it yourself.)


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 4:50 pm 
On Oct 31, 2:14 am, Bit Twister wrote:
Quote:
Not to cut your cron job submission/execution learning experience short, but
have you considered putting the backup deletion code in
the script creating the backups.  :)

You are right, of course. In this particular case it is a web app that
creates the backups. I could hack the backup creation code -- it's
open source -- but my preference is to leave the web app stock, or as
much stock as possible. That minimizes confusion when I request help
from the web app developers and makes updating or reinstalling the web
app easier. Still, your point is well taken and I agree with the
general case.


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 5:00 pm 
On Oct 30, 8:59 pm, "David W. Hodgins"
wrote:
Quote:
On Fri, 30 Oct 2009 22:31:48 -0400, Warren Post wrote:
Your point is taken that I should leave the system cron for system
cronjobs. But I am curious why what I was doing didn't work.

Is the cron daemon running?

Yes. Further, I checked in MCC to insure that it is set to run at boot.


 
 Post subject: Re: My first cron job
PostPosted: Sat Oct 31, 2009 5:50 pm 
On Oct 31, 8:03 am, Jerry Heyman wrote:
Quote:
Is there a specific reason to run this as root?

*nix allows you to create user specific crontab entries

To answer your specific question, no. But let me explain:

This thread has been educating me greatly as to cron, and so with my
growing understanding I have been likewise expanding my plans.
Originally all I sought was a way to delete certain files in a user
directory. But now I have a whole script's worth of things I'd like
done once daily, some of which need to be done as root. I suppose the
right way to do it is to run each item as only the user strictly
needed, some of which would be as root and some as user. But given
that I am just starting out I'd like to keep this as conceptually
simple as possible even if I sacrifice rightness and some safety to
begin with.

Indeed, that was my original thinking in simply dropping a new job
into /etc/cron.daily and making sure I could see it in Webmin: it
wasn't a system job, but I was trying to keep things simple, and
indeed I still don't know why that didn't work. But given that I don't
entirely know what I'm doing, then I suppose I shouldn't be mucking
about in /etc/cron.* anyway.

Hence my current thinking: do it as a user specific job as root. As
root I can do great damage, but at least I'm not risking the system
cron. So, with special thanks to Chris Johnson, here's what I'm
thinking now:

1. Save the following as /root/crontab_daily:

#!/bin/sh
# Performs regular backup and cleanup functions
# Warren Post, 31 Octber 2009
#
# Back up hard disk to DVD using dkopp
dkopp -script /root/.dkopp/jobfile_script
#
# Remove dkopp history older than 14 days
find /root/.dkopp/ -name "dkopp-hist-*" -type f -mtime +14 -delete
#
# Remove vtiger backups older than 2 days
find /home/jorge/vtigercrm_bak/ -name "backup_*" -type f -mtime +2 -
delete
#
# Remove user .xauth files older than 2 days
find /home/jorge/ -name ".xauth*" -type f -mtime +2 -delete

2. Save the following as /root/crontab to run it at lunchtime daily:

30 12 * * * nice -n 19 /root/crontab_daily

3. Then, make it so: "crontab /root/crontab"

Comments and corrections welcome as always.


 
Go to page | Previous  1 2 3 4 5  Next





SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
 © 0x61.com 2009 - Internet Forums and much more! - All rights reserved.