-1

I have the following command in my crontab to copy a file named 'data' into an existing directory named 'Archive', with a date stamp appended to it. When I run it on the command line manually, it works fine.

01 0  * * * cp /home/data /home/Archive/data.$(date +%F)

But when cron runs the above (under the same user), the file does not copy, and I get the following error:

cp: 0653-437 2018 is not a directory

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
Kevin
  • 1
  • 1
  • Which version of `date` is installed, and what's your locale? – JigglyNaga Nov 13 '18 at 14:36
  • please run `date +%F` and tell us what you get. it seems that you get a space character somewhere and the `cp` command thinks that you're trying to copy several files into a directory. – John Smith Nov 13 '18 at 14:54

2 Answers2

0

That might be a shell issue. Try putting that command inside of a script that starts

#!/bin/bash

and execute the script manually to make sure it works, then try executing it in cron.

JigglyNaga
  • 7,706
  • 1
  • 21
  • 47
msheda
  • 1
  • 1
0

The problem might be there is no such directory. This oneliner will handle dir creation for you:

01 0 * * * export NEWDIR=/home/Archive/data.$(date +%F) ; mkdir -p "$NEWDIR"; cp /home/data "$NEWDIR"

ameiji
  • 1
  • 1
  • The question specified that the `Archive` directory already exists, and the error shown is the one that results from trying to copy multiple sources. When there's a single source, and the destination doesn't yet exist, then `cp` should try to create that destination automatically (or show a different error about the source). – JigglyNaga Nov 13 '18 at 16:23