Cronjob to copy selected files

Cronjob to copy selected files

Posted by: FrankJohnson
Posted on: 2009-10-07 20:48:00

Hello. I'm trying to set up a cronjob to copy selected files from one particular directory in a website to another directory in that same website.

I'm trying to use rsync in this way:

Re: Cronjob to copy selected files

Posted by: Atropos7
Posted on: 2009-10-08 00:21:00

In reply to:

Hello. I'm trying to set up a cronjob to copy selected files from one particular directory in a website to another directory in that same website.


Tip: If the command is complex, or you haven't thoroughly tested it yet to satisfaction, don't use it for the cronjob. Use a shell script instead, and put the command in the shell script. Then you don't have to modify the crontab in order to debug the command.

In reply to:

rsync --filter '- *_thumb.jpg' --filter '- *_medium.jpg' -e ssh -av /home/.newie/username/domain/images/gallery/ /home/.newie/username/domain/slideshow/


This isn't a remote operation, so drop the -e argument.

A shell script might look like this:

#!/bin/bash
SOURCE=$HOME/domain/images/gallery/
DEST=$HOME/domain/slideshow/
FILTER="--exclude=*_thump.jpg --exclude=*_medium.jpg"
OPT=-av
# Command line argument handling
while [ $# -gt 0 ]; do
case "$1" in
-q|--quiet)
# Redirect stdout and stderr so there is no output
exec &>/dev/null
;;
-d|--dry-run)
# Do not make changes.
OPT=-nav
;;
esac
shift # Check next set of parameters.
done
rsync $OPT $FILTER $SOURCE $DEST


Then for you crontab you can do either
1. - if you did chmod 755 on script.sh -
/home/username/path/script.sh

2. - if you did chmod the script file -
/bin/bash /home/username/path/script.sh

And you got options: -q or --quiet and -d or --dry-run



Customer since 2000 cool openvein.org

Re: Cronjob to copy selected files

Posted by: sXi
Posted on: 2009-10-08 05:26:00

rsync -av -f '- *_thumb.jpg' -f '- *_medium.jpg' ~/domain/images/gallery/ ~/domain/slideshow/




How To Install PHP.INI / ionCube on DreamHost

Re: Cronjob to copy selected files

Posted by: FrankJohnson
Posted on: 2009-10-08 08:35:00

Thanks Atropos7.

I tried what you suggested, and I think I'm getting closer. Now the email notification has this error:

Re: Cronjob to copy selected files

Posted by: FrankJohnson
Posted on: 2009-10-09 06:14:00

I was able to figure this out with a little bit of help from Dreamhost support - I was running the cronjob as the wrong user.

Thanks!
Frank

Re: Cronjob to copy selected files

Posted by: sXi
Posted on: 2009-10-09 07:55:00

That *would* be a bit of a show stopper wink




How To Install PHP.INI / ionCube on DreamHost

Re: Cronjob to copy selected files

Posted by: discoboomer
Posted on: 2009-10-10 13:26:00

Can I ask how you resolved this user issue? I think I am in the same boat.

Re: Cronjob to copy selected files

Posted by: sXi
Posted on: 2009-10-10 15:11:00

Select correct user if creating a job from within Panel.




How To Install PHP.INI / ionCube on DreamHost

Re: Cronjob to copy selected files

Posted by: discoboomer
Posted on: 2009-10-10 17:02:00

Maybe my issue is different. I have 2 users, one with ftp and one shell. The shell user does not have access (as far as I can tell) to the ftp user files. And I need to update the ftp user files with this cron job.

I think I need to either give the shell user access to ftp user files, or somehow make ftp user able to run cron job.

Re: Cronjob to copy selected files

Posted by: sXi
Posted on: 2009-10-10 17:32:00

A shell user can access an FTP user's files if group write permissions are set on the files. If you need to copy files onto the FTP user space then group write needs to be set on the target directories as well.




How To Install PHP.INI / ionCube on DreamHost

Re: Cronjob to copy selected files

Posted by: discoboomer
Posted on: 2009-10-10 18:58:00

Thanks for the quick replies, I will try it out.

Tags: ssherror messageslideshowthumbstatrsync