How to setup a cron job for rescan certain folders

hi i am using nc latest and uploaded some files via sftp.
how can i setup a cronjob that rescans the files of this folder:

probably i need to setup a php file and use the cronjob to activate that.
but im a newbie and have no glue at - any help is highly appreaciated.

Check-out the administrator guide which includes an example how the default background job need to be executed using cron:

1 Like

@j-ed I don’t think that @telemarker wants to set up a normal cronjob but instead wants to schedule the command occ files:scan


correct, thats what i want!

My opinion on that is to not regularly run files:scan but instead use the external storage app for any folder that shall regularly get accessed/changed externally since it has some very practical features for this and is meant for this usecase.

hey szaimen, i cannot find the external storage app:
there are only apps available for dropobox, onedrive and googledrive.

actually i just need to run the scan every now and then when i upload large files (since this is not supported by the nc client). but my ssh is not working, so i need to make nc rescan somehow from the server. maybe i could run a .php or .sh file via url?

The app is actually bundled within the server software itself: server/apps/files_external at master · nextcloud/server · GitHub

thanks, yes i can see it on the server and just found it under your apps.

ok, i set up the external drive - but it runs pretty slow - maybe its scanning right now. but i can see just the folders and files - no thumbnails of images at all.

also i got some errors popping up.

to me this makes not much sense - why should i setup a subfolder from /data as an external drive, if its allready at the same server. looks like this slows down performance of the whole system.

so if you can provide me with the solution to rescan folders via cronjob it would be highly appreciated.

basically a cronjob would look like this:
edit crontab of the werbserver user:
sudo crontab -u www-data
add a line e.g. like this: 0 */1 * * * php -f /path/to/nextcloud/occ files:scan --all
which would run the scan every hour. Afterwards save the file.

1 Like

thanks, i looked in the cron manager from my hosting and i can only run an url in a certain time interval (e.g. daily from 6-12 a.m.)
this means i could setup a cron that runs a subdomain.
how can i put your files:scan --all command onto the server so it gets activated everytime i open this url
sorry my server seems to be a bit limited.

Sry, I cannot help with that. It also looks like a security issue to me if you just open an url which runs any code on your server but I could be wrong.

actually i can set a user name and password.

1 Like

hello szaimen,
i make a workaround and can now use ssh from my android device.
i easily could connect to the server, walk to the nextcloud directory and tried
$ php -f /cloud/occ files:scan --all
but then i got: no input file specified.

i also tried:
$ sudo -u www-data php /cloud/occ files:scan --all
but then it says: command not found.

what i am doing wrong here? (nextcloud is installed in /cloud)

maybe try sudo -u www-data php -f /cloud/occ files:scan --all

hmm that throws out again:
command not found
i am running this from the /cloud folder.

What does ls -l /cloud return?

from the root directory it throws:
cannot acces ‘/cloud’: no such file or directory

ls -l cloud returns the list of files and folders.

What does sudo find / -maxdepth 4 -type f -name occ return?

command not found.
could it be that sudo is not working?