Running a script out of nextcloud

I’ve written a small python script that I’d like to periodically run on my Pi. I wrote it on my PC and put it on my Pi via Nextcloud, because it has to have access to files in my cloud.

My plan is:
Call the script via cron
Script moves a file from one folder in the cloud to another
A few minutes later, another cronjob with ncc files:scan is called to detect the changed file.

Currently, I’m stuck on setting up a venv in the nextcloud folder on the Pi. Trying to login as www-data (so that the venv is accessible by the cloud) just tells me “This account is currently not available”. I’m logged in as root

What can I do to fix this?

User www-data is a system user only without the possibility to login. If files are uploaded via NC, they should have correct permission and you can copy them easily as root user and keep permissions. As well why writing a script in python? A simple shell script will do as well.

I should have been a bit clearer: The script does more than just move a file, it posts a picture from a folder to mastodon, then moves the picture (so it does not get posted again). It should use pictures from my PC and from my phone, so my cloud was the easiest way to set that up (SSH is disabled from outside my network). The permission problems come strictly from creating a venv for the python script on my pi.

I realized that venv is system dependend, so I just kept it out of the nextcloud and the posting works fine. Now, my problem is, that

1 * * * * ncc files:scan Green --path="/Green/files/Dateien/Mastodonbot/"

in my crontab is not run. If I start it manually as root, it works. It does not work on the crontab from root nor www-data.

The ncc command is a shotcut for sudo -u www-data php /var/www/nextcloud/occ which maybe does not work inside of cron, so instead of ncc try
su www-data php /var/www/nextcloud/occ

1 * * * * su www-data php /var/www/nextcloud/occ files:scan Green --path="/Green/files/Dateien/Mastodonbot/"

or you could try the crontab for the user www-data
sudo crontab -u www-data -e
and add the line

1 * * * * php /var/www/nextcloud/occ files:scan Green --path="/Green/files/Dateien/Mastodonbot/"
1 Like

The last option is the cleanest one. The www-data crontab also contains the regular NC cron call, from which you can borrow part of the syntax.

Thank you, it works flawlessly.