Hi Matt, --- Matt Johnson <johnsonmlw@yahoo.com> wrote: >
:-) Hmmm, which user are you using to ftp the files
I've only tried to run the script as root (using .netrc in /root).
over? And which ftp daemon are you using?
I don't know :(
No worries -- most likely it is the Berkerley FTP daemon.
I'd be more
inclined to write another "wrapper" shell script that actually "su"'s to the "ftp" user and then uploads it that way.
Is a 'wrapper' a script that calls another script?
It is indeed.
The reason most likely, as to why it doesn't
work is
because all crom services that are ran, are ran as "root" which would give you permission errors.
One other possibility is the environment. When you log in, a number of environment variables are set, such as $HOME.
That would explain it. When I run it a root manually, obviously i have /root set as my home. But then if that weren't set for the cron job, it wouldn't find the .netrc file. I like the sound of that. I'll let you know.
Good. Dont forget to "chown" the ".netrc" file for the user to whom your going to copy the file across to, thus if you were copying it to user "thomas".... [root@hostserver]# cp ~/.netrc /home/thomas [root@hostserver]# chown thomas.users /home/thomas/.netrc
This almost certainly isn't being set for the cron job. If use use
su - <username> -c <scriptname>
in your cronjob, then minus sign tells su to use that user's environment and most of the variables required are initialised.
So, I plan to move my webupdate script from /etc/cron.daily to /root. Then write a 'wrapper' (?) script to put in cron.daily:
su - root -c /root/webupdate
I'm thinking that $HOME will then be set by this wrapper? And the webupdate script ran being able to use /root/.netrc.
No -- the purpose of the wrapper was for the "su" command. There are two pre-requesites that you have failed to grasp :-) 1) NEVER EVER execute FTP requests as root. ALL distributions don't allow it (unless you've edited "/etc/ftpusers") so it will fail with an error message.
If there's any glaring errors in my thinking, please shout.
OH I SHOUTED ALRIGHT :-) :-)
Thanks for the replies. It's all a curve!
Indeed -- and one that you're learning rapidly You might try something like: ------------------cut--------------------------------- #!/bin/bash su - someuser -c /usr/bin/webupdate ----------------------end-cut------------------------- Use the above for your cronjob (changing the values as appropriately). Furthermore, make sure that your original "/root/webupdate" file is moved to "/usr/bin" (chmod +au /usr/bin/webupdate) -- and change it if need be (although you shouldn't need to).
(I'm only in that school on a Thursday, otherwise I would have just tried all this, rather than post my intentions for peer review!)
Are you a student then (sixth form). Im 19 and an on my second year of a degree in Southampton :-) Kind Regards, -- Thomas Adam ===== Thomas Adam "The Linux Weekend Mechanic" -- www.linuxgazette.com __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com