{"id":1566,"date":"2020-01-29T00:00:55","date_gmt":"2020-01-28T23:00:55","guid":{"rendered":"https:\/\/nuage.ch\/site\/?p=1566"},"modified":"2020-01-29T00:01:00","modified_gmt":"2020-01-28T23:01:00","slug":"use-your-hp-to-scan-on-a-nextcloud-folder","status":"publish","type":"post","link":"https:\/\/nuage.ch\/site\/use-your-hp-to-scan-on-a-nextcloud-folder\/","title":{"rendered":"Use your HP to scan on a nextcloud folder"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The goal of this article is to explain how you can scan directly on your nextcloud solution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 &#8211; you have a nice PDF. It&#8217;s a very good way to archive documents!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have a linux based computer that is used as a nextcloud \/ owncloud data storage and backup facility &#8211; my printer scan on this computer that contains a samba share.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1: Configure nextcloud<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You need to install nextcloud on this computer. It&#8217;s not the scope of this article to explain how to do it. My nextcloud installation is running with the user www-data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will need to install the &#8220;groupfolder&#8221; extension and create a shared folder &#8220;Scanner&#8221;. <em>You can sync one of your personal folder too&#8230; but I use the scanner for my all family.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s get the id of the group you have just created. Go in the nextcloud folder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u www-data php -f occ groupfolders:list<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can modify files locally and run the following command to scan for changes. 1 is the id that was given just before.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo -u www-data php -f occ groupfolders:scan 1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will need to know where this folder is stored. In my case it&#8217;s in &#8220;\/home\/cloud\/data\/__groupfolders\/1\/&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2: Configure samba<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now we need to create a guest samba share. It&#8217;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 \\\\192.168.1.10\\MyDocuments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In my \/etc\/samba\/smb.conf, I have the following configuration.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>[scanner]<br>comment = Scanner HP Printer<br>path = \/home\/cloud\/data\/__groupfolders\/1\/<br>read only = no<br>browsable = yes<br>public = yes<br>writable = yes<br>guest ok = yes<br>force user = www-data<br>force group = www-data<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">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\/.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3, notify the changes to nextcloud<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I installed inotify-tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;ve created a small script called <strong>monitor-scan.sh<\/strong> (You will need to configure it based on your settings).<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>!\/bin\/bash<br><br>cd \/home\/cloud\/nextcloud<br><br>while [ 1 ]<br>do<br>inotifywait -e attrib \/home\/cloud\/data\/__groupfolders\/1\/<br>sleep 5<br>php -f occ groupfolders:scan 1<br>done<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">This script will wait for an &#8220;attrib&#8221; notification in the folder that store the configurations. It&#8217;s a way to track that a document was uploaded by the printer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We have an infinite loop that do that again and again. Try to run the script (sudo -u www-data .\/monitor-scan.sh) and verify what&#8217;s happening when you scan a document. It should appear in your web interface of nextcloud.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s start it when you start your computer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Edit your cron, probably with<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>crontab -u www-data -e<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">You should have the first cron that was installed with nextcloud. Add the second cron (with the correct path).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">*\/5 * * * * php -f \/home\/cloud\/nextcloud\/cron.php<br>@reboot \/home\/cloud\/monitor-scan.sh >>\/tmp\/scanner-monitor.log<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now restart your computer&#8230; and it everything is working you are done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[11],"tags":[],"class_list":["post-1566","post","type-post","status-publish","format-standard","hentry","category-linux-and-servers"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p50cYU-pg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/posts\/1566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/comments?post=1566"}],"version-history":[{"count":0,"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/posts\/1566\/revisions"}],"wp:attachment":[{"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/media?parent=1566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/categories?post=1566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuage.ch\/site\/wp-json\/wp\/v2\/tags?post=1566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}