1

this is my script "backup.sh":

#!/bin/bash


date=$(date +"%m-%d-%Y_%r")

mmv -r "uploads/temp/*" "#1\ '$date'"

mv /ftphome/uploads/temp/* /ftphome/uploads/arch/

My dir structure is like that:

dr-xr-xr-x 9 it2 it2 4096 Feb 29 12:09 arch
drwxrwxr-x 2 it2 it2 4096 Feb 29 12:09 temp

When I try to execute script from console all is working - as root, because otherwise I get an error "directory uploads/temp/ directory not allow writes" <- I set this permission on purpose.

Unfortunately when I'm try to start this script by corn, mmv command doesn't execute, and all files move to "arch" directory without suffix.

I was trying to change chmod permission to 777 for "temp" dir, but it doesn't help. I edited crontab as root, so it should work as root (that info I read in this topic: How to run a cron job using the sudo command ).

BTW, it is like i try to execute script by cron (every minute is for testing):

* * * * * /ftphome/backup.sh
KalikDev
  • 402
  • You shouldn't rely on a relative path uploads/temp/ for the source directory. You may need to use full paths for the commands as well e.g. /usr/bin/mmv. Also, '$date' will likely not be expanded because of the single quotes. – steeldriver Feb 29 '16 at 14:24
  • @steeldriver No, set PATH rather than using absolute paths to commands. – geirha Mar 02 '16 at 07:02

1 Answers1

1

You need to cd to the correct directory first. Cron starts you off at /.

#!/bin/bash
date=$(date +"%Y-%m-%d_%r")

cd /ftphome || exit

mmv -r "uploads/temp/*" "#1\ '$date'"

mv /ftphome/uploads/temp/* /ftphome/uploads/arch/

On a side note, don't put .sh extension on a bash script. It's misleading since sh is not bash.

geirha
  • 46,101