4

I am running this simple script and I am trying to create a cron job so that the file gets copied to my thumbdrive (with the new name)

 sudo cp /home/pi/NewLog.log /media/usb sleep 20 cd /media/usb sudo mv -f NewLog.log NewLog-$(date '+%FT%T').log sudo cp /dev/null /home/pi/NewLog.log 

But I am getting the error

mv: cannot move ‘NewLog.log’ to a subdirectory of itself, ‘NewLog-2016-05-04T14:19:24.log’

ls -l in /media/usb shows this,

-rwxr-xr-x 1 root root 42747 Nov 30 16:18 backup xml.txt -rwxr-xr-x 1 root root 407517 Apr 28 11:07 Comparision log.log -rwxr-xr-x 1 root root 4174 Apr 29 18:16 Friday.txt drwxr-xr-x 2 root root 16384 May 4 14:12 Logs -rwxr-xr-x 1 root root 594588 May 3 09:28 MachineHMAX___.log -rwxr-xr-x 1 root root 737280 May 4 17:23 NewLog.log -rwxr-xr-x 1 root root 415960 May 3 10:21 NewLog__.txt -rwxr-xr-x 1 root root 267989 Apr 28 09:28 NewLog.txt drwxr-xr-x 2 root root 16384 May 17 2015 System Volume Information -rwxr-xr-x 1 root root 276588 Apr 29 11:05 Thur_a.txt -rwxr-xr-x 1 root root 183600 Apr 29 11:05 Thur_b.txt -rwxr-xr-x 1 root root 276370 Apr 28 11:22 Thurs.txt -rwxr-xr-x 1 root root 460185 Apr 28 13:42 Thur.txt -rwxr-xr-x 1 root root 676739 May 3 13:44 Tuesday.Log -rwxr-xr-x 1 root root 8032 Apr 23 17:36 unix2dos.zip -rwxr-xr-x 1 root root 7364727 May 4 08:45 Wednesday.txt 
8
  • Beside the issue, is there a reason you don't just run sudo cp /home/pi/NewLog.log /media/usb/NewLog-$(date '+%FT%T').log ? Commented May 4, 2016 at 14:55
  • No, when i did that it says cannot create regular file. I want the file to be timestamped and copied to the USB everyday at a particular time and then i clear the file , Commented May 4, 2016 at 15:03
  • so you are not even able to copy the file to media ? Commented May 4, 2016 at 15:16
  • Well i am able to cp if I do sudo cp /home/pi/NewLog.log /media/usb....but if I try the first comment its not working Commented May 4, 2016 at 15:17
  • After you do the first 3 steps, what do you see if you do ls -l? Commented May 4, 2016 at 15:20

1 Answer 1

3

The colon (:) character is not a valid character in file names on a FAT/VFAT filesystem. The rename system call (which is what mv calls under the hood) returns the EINVAL status code to indicate this. Attempting to move a directory to become a subdirectory of itself returns the same status code; mv only lists one of the possible error reasons.

Use a different time format. The ISO 8601 format may be a formal standard, but its punctuated form is annoying to deal with. Use the unpunctuated form, or another representation altogether. You aren't currently following ISO 8601 anyway since you omitted the timezone indication, which is bad since it makes the time ambiguous. This form is ISO-compliant, uses UTC time, and doesn't include any punctuation:

date -u '+%Y%m%dT%H%M%SZ' 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.