You are not logged in.

#1 2009-05-04 20:50:17

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

[Solved] Setting Up A Cron Job

I want to set up a cron job that will copy (update) my download folder that contains all my linux related stuff to the linux downloads folder contained in my windows downloads folder. I know how to set up crontab but vi(m) confuses me since it opens crontab as a temp file and I dont know what to call it when I try and save it. I tried using EDITOR=nano crontab -e but it still opens vim hmm

heres the line I want to input into crontab:

0 3 * * * cp -Ru /home/bran/downloads/* "/media/mybook/Downloads/Linux Downloads/"

Last edited by brando56894 (2009-05-05 23:12:05)

Offline

#2 2009-05-04 20:56:54

phil90
Member
Registered: 2008-09-13
Posts: 36

Re: [Solved] Setting Up A Cron Job

Good  afternoon brando56894,

You can use this command
export VISUAL=nano


Next time you will type crontab -e it will open nano.



Regards,

Last edited by phil90 (2009-05-04 20:58:55)

Offline

#3 2009-05-04 21:03:13

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [Solved] Setting Up A Cron Job

$ nano foo.cron
-- type whatever in your sweet editor wink --
$ crontab foo.cron


you could also learn vim, it's not hard (press 'i' to insert text then escape and type ':wq' to write and quit the file)

this guide is good (for cron, not vim):

http://www.scrounge.org/linux/cron.html

also can i recommend:

0 3 * * * cp -Ru /home/bran/downloads/* /media/mybook/Downloads/Linux\ Downloads/

Last edited by brisbin33 (2009-05-04 21:05:24)

Offline

#4 2009-05-04 22:19:54

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [Solved] Setting Up A Cron Job

brando56894 wrote:

... vi(m) confuses me since it opens crontab as a temp file and I dont know what to call it when I try and save it.

That's normal -- it's not vi(m), it's crontab. It copies to a temp file, you edit the temp file and then crontab does sanity checking on the file before moving it to the correct location.

This way if you completely fsck it, it will detect it, alert you, and then if you choose to cancel what you did, it just doesn't move the temp file over what was there before.

Last edited by fukawi2 (2009-05-04 22:20:43)

Offline

#5 2009-05-04 23:14:32

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] Setting Up A Cron Job

thanks for the info everyone big_smile

brisbin33 wrote:

$ nano foo.cron
-- type whatever in your sweet editor wink --
$ crontab foo.cron

you could also learn vim, it's not hard (press 'i' to insert text then escape and type ':wq' to write and quit the file)

also can i recommend:

0 3 * * * cp -Ru /home/bran/downloads/* /media/mybook/Downloads/Linux\ Downloads/

some good info here, a) didnt know you could add jobs like that b) didnt know you could enter insert mode by just pressing 'i' i always did :startinsert which was pretty annoying and :save [filename] :quit c) whats the difference between "Linux Downloads" and Linux\ Downloads?

Offline

#6 2009-05-05 13:20:18

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [Solved] Setting Up A Cron Job

hey, that was my bad.  i guess it's a preference that i incorrectly characterized as a best practice.  too much bash scripting makes me aware of when things don't _need_ to be double quoted... doesn't mean they _shouldn't_ be double quoted. 

getting into that habit of the down slash in front of spaces might come in handy though b/c you would know to also put it in front of symbols like $ and ? which wouldn't behave well inside double quotes.  however, in your case, either way works just fine.

i'll trade that bit of bum advice for some good advice though: look into rsync, it works very similar to cp except it won't spend all that time/energy copying files that are already there.  does my nightly backup (~205 GB) in less than 3 minutes.

oh, and don't forget to add [solved] if you get this all working. smile

Offline

#7 2009-05-05 16:32:18

thisperishedmin
Member
Registered: 2008-11-04
Posts: 164

Re: [Solved] Setting Up A Cron Job

you could also just cd to /etc/cron.d and then make a new file...for example...

cd /etc/cron.d
sudo nano download-transfer.cron

edit your file as you want, and quit.

I always found it easier to manage tasks like this in seperate .cron files, and keep anything system necessary in crontab -e... which is more or less nothing i wrote.

Hope this is just some more  helpful info. as you can see there are a ton of different ways to do this in the end!

However, a big +1 for learning Vi...the basics arent really bad at all.  Once you conceptually understand the modal theory - the basic commands are just a small stretch away.

if you need more  help beyond what you can find on the web feel free to PM me or anything instead of cluttering this up...I'm not a pro but i can comfortably use Vi(m).

good luck!

Offline

#8 2009-05-05 23:11:51

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: [Solved] Setting Up A Cron Job

I tried adding the job to /etc/cron.daily but that didnt seem to have any effect on anything, ive been learning vim on and off for awhile now but its alot to learn and its completely different than anything else. I know the basic stuff (save, quit, quit!, startinsert) but thats about it. I think the best feature I love about it is the syntax highlighting since i usually use nano and it doesnt seem to work even when i tried to enable it in the config file.

brisbin33 wrote:

hey, that was my bad.  i guess it's a preference that i incorrectly characterized as a best practice.  too much bash scripting makes me aware of when things don't _need_ to be double quoted... doesn't mean they _shouldn't_ be double quoted. 

getting into that habit of the down slash in front of spaces might come in handy though b/c you would know to also put it in front of symbols like $ and ? which wouldn't behave well inside double quotes.  however, in your case, either way works just fine.

i'll trade that bit of bum advice for some good advice though: look into rsync, it works very similar to cp except it won't spend all that time/energy copying files that are already there.  does my nightly backup (~205 GB) in less than 3 minutes.

oh, and don't forget to add [solved] if you get this all working. smile

haha its cool, i was actually thinking about using rsync originally but then i was looking up a guide for it and it seemed to complex to do something simple like I needed to do. my linux downloads folder is only about 400 or so mb and the u flag updates only changed files so it doesnt take that long anyway.

Offline

#9 2009-05-06 02:59:02

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [Solved] Setting Up A Cron Job

rsync -av --delete /home/source /mnt/dest

smile

Offline

#10 2009-08-25 16:19:24

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [Solved] Setting Up A Cron Job

fukawi2 wrote:
brando56894 wrote:

... vi(m) confuses me since it opens crontab as a temp file and I dont know what to call it when I try and save it.

That's normal -- it's not vi(m), it's crontab. It copies to a temp file, you edit the temp file and then crontab does sanity checking on the file before moving it to the correct location.

This way if you completely fsck it, it will detect it, alert you, and then if you choose to cancel what you did, it just doesn't move the temp file over what was there before.

There's no sanity checking---at least not in dcron. It's not like visudo. All that dcron's crontab does is make sure the temp file gets copied to the right place, with the right metadata, and that a cron.update file gets generated so that a running crond will notice the updated file within the next minute. (crond also does a full rescan of its crontab directories once an hour, even without the cron.update file.)

Offline

#11 2009-08-26 00:13:12

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: [Solved] Setting Up A Cron Job

I thought it did a basic column count to make sure the first 5 (min, hour, dom, month, dow) were valid, and then there was 'something' (ie a command) after it?

Offline

#12 2009-08-26 00:25:26

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [Solved] Setting Up A Cron Job

dcron doesn't do this. I'm freshly acquainted with the source because I've just forked it. But vixiecron might do that.

Offline

Board footer

Powered by FluxBB