Cronjob to copy selected files

software development

#1

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:


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

but the email notice is showing me this error:


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

then it’s correctly listing all the files that qualify to be copied per the filters, then continuing with the error message like this:


batch/
rsync: recv_generator: mkdir “/home/.newie/username/domain/slideshow/batch” failed: Permission denied (13)
rsync: stat “/home/.newie/username/domain/slideshow/batch” failed: No such file or directory (2)
rsync: mkstemp “/home/.newie/username/domain/slideshow/.3838424022_2e54bef48a_b.jpg.APi98H” failed: Permission denied (13)

and then it lists that same last line once for each image it is trying to copy.

Any ideas on what’s causing the problem? I’m definitely not an expert at this (at all!).

Any help anyone can offer me would be greatly appreciated.

Thanks,

Frank


#2

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.

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

A shell script might look like this:

[code]#!/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[/code]
Then for you crontab you can do either

    • if you did chmod 755 on script.sh -
      /home/username/path/script.sh
    • 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


#3

Maximum Cash Discount on any plan with [url=http://www.dreamhost.com/r.cgi?384814/signup|MAXCASH]MAXCASH[/url]

[url=http://sxi.sabrextreme.com/forum]How To Install PHP.INI / ionCube on DreamHost[/url]

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#4

Thanks Atropos7.

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


rsync: failed to set permissions on “/home/username/domain/slideshow/.”: Operation not permitted (1)

I chmod’d the slideshow directory to 777, but I’m getting that error.

Any ideas?

Thanks!
Frank


#5

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


#6

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

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#7

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


#8

Select correct user if creating a job from within Panel.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#9

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.


#10

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.

Maximum Cash Discount on any plan with MAXCASH

How To Install PHP.INI / ionCube on DreamHost


#11

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