1

I am on Debian. I try to make a cron job for youtube-dl. It consists of a daily script, starting at midnight. When I execute the script manually, everything is working perfectly. However, when I use the cron job, I have got an error like this :

ERROR: unable to open for writing: [Errno 13] Permission denied: '/media/Video/...

The cron is the following :

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@daily /usr/local/bin/youtube-dl-script.sh >> /var/mail/nextcloud 2>&1

I understand, there is a permission issue somewhere, but I don't know how to solve it.

For your information :

  • owner/group of the target folder (/media/Video/) is : www-data (owner), wwww-data (group)
  • owner/group of the script is : nextcloud (owner), root (group)
  • nextcloud and root belong to the group www-data
  • and the target folder (/media/Video/) permission is 770 (owner/group group can read/write/execute, others can't do anything).

Please, could you help me ? I have seen a similar topic but the solution was not successful as the problem was not exactly the same. Thank you very much.

EDIT (old status) : so far, I have tried to copy my script (youtube-dl-script.sh) in /etc/crontab.daily folder, by respecting the rules (removing the .sh extension and script owned by root / group root). And checking with cat /etc/crontab gives me this output :

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

So, normally, it should have worked at 6:25 AM this morning, but it didn't !

I have discovered that other scripts have -xas a final bit, therefore, I have made chmod +x youtube-dl-script.

  • Before that, the script is -rwxr-x--- 1 root root 1682 juin 16 02:24 /etc/cron.daily/youtube-dl-script.

  • Now, it is -rwxr-x--x 1 root root 1682 juin 16 02:24 /etc/cron.daily/youtube-dl-script.

I have now to wait until tomorrow 6:25 AM to see if this works.

EDIT 2 (current status) : so it doesn't work. I have even made chmod 755 in order to have the same persmissions as all other scripts, and I have reboot the server, but it does not work.

What is very strange is that if I do run-parts --test /etc/cron.daily, my script is listed so it should be runned by cron.daily

Please, if you have any idea, feel free to inform me. Thank you.

14
  • Can't you download to /home/user/media instead? Please also note cron doesn't inherit any environment variables
    – unixandria
    Jun 15, 2019 at 23:39
  • The owner/group of the script don't really matter here - it's the owner/group of the cron process. Whose crontab are you placing this in? Jun 15, 2019 at 23:44
  • @steeldriver : the crontab is stored in /var/spool/cron/crontabs/. @colbycdev : no because the folder is in an external drive (so it is in /media folder mandatory). Thank you both, please feel free to help me ! Jun 15, 2019 at 23:53
  • @prog-amateur how are you setting up crontab? From crontab - e on your user? Also can you access the folder from command line yourself?
    – unixandria
    Jun 15, 2019 at 23:57
  • 1
    Note that if you choose to place your script in /etc/cron.daily, its name must conform to the rules described in man run-parts (in particular, it cannot have a .sh or any other "dot extension") and it must be owned by root. See the DEBIAN_SPECIFIC section of man cron Jun 16, 2019 at 0:53

1 Answer 1

0

OK, I have found the solution :

First, I have moved the script to /etc/cron.hourly, because there were no anacron installed, and because I would like to use it every hour. But it didn't worked.

Then I have run sudo service cron statusjust to check if cron service was active. It was, but I have also found an interresting warning, something like your token was expired, renew your token. So I have searched for this error message on Internet and have found that my root password needed to be renewed, otherwise cron would not work correctly. To check this, I had to use sudo chage -l root which showed that my root password was expired.

Therefore, I have renewed my root password with sudo passwd root and I have checked again with sudo chage -l root which showed that the password is now OK. Now, everything is running fine, and cron is working as expected !

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .