Koozali.org: home of the SME Server

New cron job - newbie

Norrie

New cron job - newbie
« on: October 11, 2001, 03:07:05 PM »
Hi,

I wish to get my e-smith server to automatically fetch some files by anonymous ftp on a weekly basis but I'm not sure where to start.

Here's how I think I should do this...

1 Create a script to fetch the files.
2 Create a custom crontab fragment to run the script weekly.

I this the way to go?
If so, I have some problems....

I've never actually written a script before and don't know where they should be stored.
I've never written a custom template.
I've never written a cron job before and I don't know where it should be stored either.

Can anyone point me in the right direction please?

Regards

Norrie
8o)

Norrie

Re: New cron job - newbie
« Reply #1 on: October 11, 2001, 03:42:36 PM »
Hi,

I've written a text file that looks like this...

user anonymous 123abc@domain.com
lcd /home/e-smith/files/ibays/temp
binary
mget *
quit

Running...

ftp -in ftp.remotesite < textfilename

works fine so I guess I'm on the right track but the file is stored in /root/home and I don't think the script or cron job should be run as root should it?

Anymore suggetions?
Regards

Norrie
8o)

P Kidd

Re: New cron job - newbie
« Reply #2 on: October 13, 2001, 01:19:38 AM »
newbie to newbie
the crontab format is very simple, check man crontab
adding it to the e-smith template system is very simple, check Customizing the System at e-smith.org, or this explanation from Fran Boon
http://forums.contribs.org/index.php?topic=10334.msg38959#msg38959

the "fragment" or file just contains the line you want to add to crontab - the e-smith template system then adds that line into the appropriate configuration file (by doing an expand-template, see references above), manipulated by the rather simple file naming scheme

Norrie

Automatic ftp
« Reply #3 on: October 19, 2001, 04:36:47 PM »
Hi,

I wish to get my e-smith server to automatically fetch some files by anonymous ftp on a weekly basis

Here's what I've done so far

Logged in as root
Created a script to fetch the files.
Let's say the script is called getfiles.  I've created it in /home/e-smith/files/users/admin/home and it looks like this...

#! /bin/bash
# Get files from server via anonymous ftp
echo Getting files...
ftp -i <<**
open ftp.someserver.com
lcd /home/e-smith/files/ibays/temp
binary
mget *
bye
**
echo Done!

Created ~/.netrc in the same directory which looks like this...

machine ftp.someserver.com
login anonymous
password 123abc@mydomain.com

chmod ugp+x getfiles
chmod go-rwz .netrc

using mc I "chowned" (if that's the right term) the files to admin.
In the same admin/home directory running ./getfiles works perfectly.

Created a custom crontab fragment to run the script weekly so Crontab now looks like this...


01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly


# Get the files
5 12 * * 5 admin /home/e-smith/files/admin/home/getfiles

# fetchmail times during office hours


The trouble is that the script didn't appear to run.  Can anyone help me here?  Should the crontab entry have ".getfiles" at the end?  Is it something to do with permissions or users?

This is my first attempt at writing a script and custom fragment.  Any help is much appreciated.

Regards

Norrie
8o)