Use your HP to scan on a nextcloud folder

The goal of this article is to explain how you can scan directly on your nextcloud solution.

In my home, I have a printer from HP that is connected to my network. One of the nice feature of this printer is to be able to scan a list of documents. You put the list of documents, scan, and voila – you have a nice PDF. It’s a very good way to archive documents!

I have a linux based computer that is used as a nextcloud / owncloud data storage and backup facility – my printer scan on this computer that contains a samba share.

Step 1: Configure nextcloud

You need to install nextcloud on this computer. It’s not the scope of this article to explain how to do it. My nextcloud installation is running with the user www-data.

You will need to install the “groupfolder” extension and create a shared folder “Scanner”. You can sync one of your personal folder too… but I use the scanner for my all family.

Let’s get the id of the group you have just created. Go in the nextcloud folder.

sudo -u www-data php -f occ groupfolders:list

You can modify files locally and run the following command to scan for changes. 1 is the id that was given just before.

sudo -u www-data php -f occ groupfolders:scan 1

You will need to know where this folder is stored. In my case it’s in “/home/cloud/data/__groupfolders/1/”.

Step 2: Configure samba

Now we need to create a guest samba share. It’s not in the scope of this article to explain how to install it. As a reminder samba is a way to share folder similar to \\\MyDocuments.

In my /etc/samba/smb.conf, I have the following configuration.

comment = Scanner HP Printer
path = /home/cloud/data/__groupfolders/1/
read only = no
browsable = yes
public = yes
writable = yes
guest ok = yes
force user = www-data
force group = www-data

I restart samba (/etc/init.d/smbd restart) and configure my printer to scan in this folder. When I scan a document, now it should appear in /home/cloud/data/__groupfolders/1/.

Step 3, notify the changes to nextcloud

I installed inotify-tools.

I’ve created a small script called (You will need to configure it based on your settings).


cd /home/cloud/nextcloud

while [ 1 ]
inotifywait -e attrib /home/cloud/data/__groupfolders/1/
sleep 5
php -f occ groupfolders:scan 1

This script will wait for an “attrib” notification in the folder that store the configurations. It’s a way to track that a document was uploaded by the printer.

When a notification occur, we launch a command to notify nextcloud that we have changed a file. The file then will appear in your nextcloud folder!

We have an infinite loop that do that again and again. Try to run the script (sudo -u www-data ./ and verify what’s happening when you scan a document. It should appear in your web interface of nextcloud.

Now let’s start it when you start your computer.

Edit your cron, probably with

crontab -u www-data -e

You should have the first cron that was installed with nextcloud. Add the second cron (with the correct path).

*/5 * * * * php -f /home/cloud/nextcloud/cron.php
@reboot /home/cloud/ >>/tmp/scanner-monitor.log

Now restart your computer… and it everything is working you are done.

One thought on “Use your HP to scan on a nextcloud folder

  1. Claus Heine Reply

    Could you also post a version of your /etc/samba/smb.conf? I am just asking because I have the issue that I can only connect as guest from my printer to the Samba server (i.e. without password) when I fix the printer to support either only SMB1/CIFS or SMB2, also enabling SMB3 in the printer settings makes the password-less connect fail.

Leave a Reply

Your email address will not be published. Required fields are marked *