1

I've written a python script that handles uploads of videos in a directory to YouTube using YouTube's API and then moves each file out of that directory. It's meant as a cron job and the upload portion works but for some reason it stopped being able to move the files. I can't figure out why it can't move the files. The cron job is being run as the user 'joe'.

This is the error I get in the output:

mv: cannot stat '/home/joe/KM/queue/FC9682GS01-I04 WMOMANAAAA.mp4': No such file or directory

Here is a sample of the command being called via the python script using os.system() :

/usr/local/bin/youtube-upload --title="FC9682GS33-I02 WMOMAA6AAB  FLASHWAVE 7500 FW7500 GB ETHRNT MXPD" --description="FC9682GS33-I02 WMOMAA6AAB  FLASHWAVE 7500 FW7500 GB ETHRNT MXPD" --tags="FC9682GS33-I02,WMOMAA6AAB,FLASHWAVE 7500,FW7500 GB ETHRNT MXPD" --client-secrets="/home/joe/KM/KM-client-secret.json" --privacy public "/home/joe/KM/queue/FC9682GS33-I02 WMOMAA6AAB.mp4" && mv "/home/joe/KM/queue/FC9682GS33-I02 WMOMAA6AAB.mp4" "/home/joe/KM/completed/FC9682GS33-I02 WMOMAA6AAB.mp4"

Output of ls -la KM run from ~/:

ls -la KM
total 384
drwxr-xr-x  8 joe joe   4096 Feb  1 13:49 .
drwxr-xr-x 19 joe joe   4096 Feb  1 13:49 ..
drwxr-xr-x  2 joe joe 147456 Feb  1 08:15 completed
drwxr-xr-x  2 joe joe   4096 Jan 25 00:26 data
-rwxr-xr-x  1 joe joe    443 Dec 28 11:13 KM-client-secret.json
drwxr-xr-x  3 joe joe   4096 Jan 24 23:07 openshot
drwxr-xr-x  2 joe joe 192512 Feb  1 08:15 queue
drwxr-xr-x  2 joe joe   4096 Jan 26 10:16 temp
drwxr-xr-x  2 joe joe   4096 Jan 24 23:14 templates
-rwxr-xr-x  1 joe joe   4198 Feb  1 13:49 upload-cron.py
-rwxr-xr-x  1 joe joe   4320 Jan 24 19:03 upload.py
-rwxr-xr-x  1 joe joe   3804 Jan 25 01:30 video-generator.py

And the permissions on the file in question as it sits in /home/joe/KM/queue/:

ls -la "FC9682GS33-I02 WMOMAA6AAB.mp4"
-rwxr-xr-x 1 joe joe 5520724 Jan 26 06:21 FC9682GS33-I02 WMOMAA6AAB.mp4

Cron job looks like this:

* 6 * * * /usr/bin/python /home/joe/KM/upload-cron.py

UPDATE:

In my debugging, I decided to try adding an initial mv command. I adjusted the os.system call to look like this:

mv "/home/joe/KM/queue/3AL46325BA SNUXYV0AAA.mp4" "/home/joe/KM/temp/3AL46325BA SNUXYV0AAA.mp4" && /usr/local/bin/youtube-upload --title="3AL46325BA SNUXYV0AAA  1641 SX RISC PROCR BOARD" --description="SNUXYV0AAA USED ALCATEL PARTS" --tags="3AL46325BA,SNUXYV0AAA,1641 SX,RISC PROCR BOARD" --client-secrets="/home/joe/KM/KM-client-secret.json" --privacy public "/home/joe/KM/temp/3AL46325BA SNUXYV0AAA.mp4" && mv "/home/joe/KM/temp/3AL46325BA SNUXYV0AAA.mp4" "/home/joe/KM/completed/3AL46325BA SNUXYV0AAA.mp4"

This change has fixed the issue. I cannot explain the mechanism of the fix. However, if I change it back to the original string being pushed via os.system, it breaks again.

  • 1
    How is the script implemented, first of all ? and why are you using mv in python script ? Python has it's own set of utilities for that – Sergiy Kolodyazhnyy Feb 1 '17 at 19:04
  • This error was generated via a cron job. I have since commented out that cron job and will manually run it again tomorrow in a tmux session to see if it has the same results. It IS uploading the videos to YouTube. mv is after a && so if youtube-upload isn't successful, the file isn't moved. Simple and efficient progress tracking. – Cas Feb 1 '17 at 19:14
  • ok, how did you set up the cron job then ? What's the exact command – Sergiy Kolodyazhnyy Feb 1 '17 at 19:47
  • Updated original post with the crontab entry that has now been commented out. – Cas Feb 2 '17 at 2:03
  • I'm going to debug by adding a mv command in front of the command to youtube-upload using another &&. I'll mv the file to a temp directory, upload from that directory, then mv to the completed directory. This will allow me to debug the mv command issue without burning up API quota for YouTube and see if maybe the youtube-upload command is preventing the latter mv command from moving the file. (Maybe it isnt closing the file.) – Cas Feb 2 '17 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.