need help with a cron job

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

need help with a cron job

Post by Burrito »

I would like to set up a cron (that part I can do), to grab a file from my web server on a weekly basis using ftp.

the ftp part I can do *I think* (see below) also, it's just figuring out how I can grab a file with a dynmically created name:

ex:

Code: Select all

data-07-12-2006.tar.gz

that file gets created two days before I will run this cron so I need a way to grab the file with the name of two days prior.
I currently have this set up and working using php to generate a file called script.ftp that looks something like this:

Code: Select all

open 88.88.88.88
user administrator
somepassword
lcd c:\mylocalfolder\
get data-07-12-2006.tar.gz
quit
I call that file with a windows batch file that looks like this:

Code: Select all

ftp -n -s:script.ftp
all works great. but since I want to move this job over to my new ubuntu box, I figured I should come up with a better way to do it.

I'm pretty sure that I should be able to do all of this on one cron (without having to create all of these extra files), but the syntax for figuring out two days ago eludes me (actually the syntax for writing a date eludes me but I didn't want to tell you that).

can anyone please shed some light on this for me?

thx,

Burr
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

on FreeBSD it would be something like this:

Code: Select all

cd /localdir/; fetch ftp://login:password@yourhost.com/path/`date --date="2 days ago" +"data-%m-%d-%y.tar.gz"`;
perhaps for linux you would substitute 'fetch' with 'wget'.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

hmm...neither of those seem to be working

here's what I get

Code: Select all

root@tacostand:/backups# fetch ftp://myun:mypass@88.88.88.88/`date --date="4 days ago"+"data-%m-%d-%y.tar.gz"`;
-bash: mypass@88.88.88.88/`date: event not found

root@tacostand:/backups# wget ftp://myun:mypass@88.88.88.88/`date --date="4 days ago"+"data-%m-%d-%y.tar.gz"`;
-bash: mypass@88.88.88.88`date: event not found
also as an aside, will those days / months have leading zeros with that format (%m-%d)? I need them to...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

I don't have a bash installed on my home computer, but I imagine you should quote some characters in the command line... perhaps second colon, or something.
First, try the part in backticks on it's own and see if it return proper file name (notice the space before + sign):

Code: Select all

date --date="4 days ago" +"data-%m-%d-%y.tar.gz"
Then try

Code: Select all

wget ftp://myun:mypass@88.88.88.88/data-07-12-2006.tar.gz
and see if it works for you.
then try to replace hardcoded filename with date command in backticks.

use

Code: Select all

info bash
as a reference manual.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

ok we're getting really close now.

I found out that my problem seems to be happening because of my password which contains a bang (!).

let's assume this is my password (afe4!ras). I get an error that says:

Code: Select all

-bash: !ras@88.88.88.88/data-07-12-2006.tar.gz: event not found
so it's dying because of my bang. I've tried it using just alphanumerics and it goes through but wont' log in (obvoiusly). How can I 'escape' my password in that string so it doesn't try to parse it literally?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

try backslash :)
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

damn it..I was just gonna post in here that I had done that and it worked...

/me feels like a complete ass...

you beat me to it!

doh!
Post Reply