📜 ⬆️ ⬇️

Small office scan optimization

Good time of day, community!

I decided to tell how in one working group the “fast” translation of a paper document into digital form was organized.

To begin, tell you what it is. And there is a working group (about 10 computers) headed by a standalone system unit, proudly referred to as a “server”. The server has a 64-bit Ubuntu Server with Samba configured.
')
As before managers were scanned: the computer was turned on, to which the HP ScanJet 2400 flatbed scanner was connected (if it was not turned on) and the document was scanned page by page with the location of the file to be saved.
Obvious disadvantages: it was necessary to turn on the computer (and then turn it off), time was spent waiting for the OS to load, the program, the scanner had warmed up for a long time before the first scan.

How it became: the manager approached the scanner, inserted the documents in a pack (up to 20 sheets), pressed a button on the scanner, took the documents. While scans have returned to their place already in the ball.
Time to get a digital copy has decreased tenfold.

Implementation

Needed was an inexpensive document scanner with the ability to connect to linux. The choice fell on the Brother ADS-2100 model.
image
So, we connect the scanner with a USB cable to the server and configure it.

1. We look, whether the scanner is connected
lsusb 
 Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 004: ID 03f0:3817 Hewlett-Packard LaserJet P2015 series Bus 001 Device 002: ID 04f9:60a1 Brother Industries, Ltd Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

2. Go to the manufacturer's website www.brother.ru and follow the links go to the welcome.solutions.brother.com/bsc/public_s/id/linux/en/index.html page for downloading drivers and software for Linux
We are looking for Download → Scanner Driver / ADS Driver / Scan-Key-Tool → for ADS models brscan4 64bit file of deb format, and also scan-key-tool 64bit file of the same format
I downloaded the driver from the working computer, then I just threw them into a ball on the server and installed it from there.

3. Go to the directory with the downloaded files and install the scanner driver
 dpkg -i brscan4-0.4.1-3.amd64.deb 
      brscan4. (   ...     108594   .)   brscan4 (  brscan4-0.4.1-3.amd64.deb)...   brscan4 (0.4.1-3) ... This software is based in part on the work of the Independent JPEG Group. 

4. We give permissions to scan under a regular user.
Open the file /lib/udev/rules.d/40-libsane.rules and add the following comment before the comment "# The following rule will disable USB autosuspend for the device"
 # Brother scanners ATTRS{idVendor}=="04f9", ENV{libsane_matched}="yes" 

5. Reboot the server

6. Similarly to paragraph 3, install the Scan-key-tool
 dpkg -i brscan-skey-0.2.4-0.amd64.deb 
      brscan-skey. (   ...     108623   .)   brscan-skey (  brscan-skey-0.2.4-0.amd64.deb)...   brscan-skey (0.2.4-0) ... 

7. Fix the configuration files. When you press a certain key, the command is launched. This is written in /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0.cfg
Its contents are:
 password= IMAGE="sh /opt/brother/scanner/brscan-skey/script/scantoimage-0.2.4-0.sh" OCR="sh /opt/brother/scanner/brscan-skey/script/scantoocr-0.2.4-0.sh" EMAIL="sh /opt/brother/scanner/brscan-skey/script/scantoemail-0.2.4-0.sh" FILE="sh /opt/brother/scanner/brscan-skey/script/scantofile-0.2.4-0.sh" SEMID=b 

On the scanner there are three buttons: enable / disable the scanner, start scanning and scanning on the USB flash drive.
It was experimentally found out that the variable FILE = is responsible for the scan button.
Change it to
 FILE="sh /home/admin/file.sh" 

Create a script /home/admin/file.sh
Script
 #! /bin/sh set +o noclobber # # $1 = scanner device # $2 = friendly name # ##   resolution=300 device=$1 ##      temp_dir=/tmp/scan_"`date +%Y-%m-%d-%H-%M-%S`" mkdir -p $temp_dir cd $temp_dir ##      if [ "`which usleep 2>/dev/null `" != '' ];then usleep 10000 else sleep 0.01 fi ##  ##    =40 ##     ##    4 ##   ##     ,     ##     tiff <u>scanimage</u> --batch-count=40 --source 'Automatic Document Feeder(centrally aligned,Duplex)' -x 210 -y 297 --device-name "$device" --resolution $resolution –format=tiff ##   tif-  jpg-   90% <u>convert</u> -quality 90% *.tif im.jpg ##   tif-   rm *.tif ##  jpg- <u>exiftool</u> -d %Y-%m-%d_%H.%M-%S%%-c.%%e "-filename<FileModifyDate" $temp_dir ##   111        ## ..     ##     find . -size +111k -exec mv {} /srv/scan \; ##      rm -r $temp_dir ##  -  saned ##    ,    root cd /srv/scan chown saned:saned *.jpg 

In the script, I stressed what was not in the system. Install / create:
a) for scanimage
 apt-get install libsane sane-utils 

b) to convert
 apt-get install imagemagick 

c) for exifrool
 apt-get install libimage-exiftool-perl 

d) create a ball / srv / scan visible on the local network as // server / scan for reading to all users

We expose the rights to the script 600

8. Not mandatory step. I changed the daemon startup script to track the status of the scanner keys / opt / brother / scanner / brscan-skey / brscan-skey as follows:
It was
 #! /bin/sh if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then if [ "$2" = "2" ];then echo ' no option :register all MFCs' echo ' -t (--terminate) :terminate this tool' echo ' -a (--add MFC) :register the specified MFC' echo ' -d (--delete) MFC :exclude the specified MFC' echo ' -p (--passwd) PASSWORD :set the password' echo ' -u (--username) USERNAMR :set the user name' echo ' -l (--list) :list the available MFCs' echo ' -m (--mailto) :mail address (scan to e-mail)' echo ' --refresh :refresh setting' echo ' --reset :reset the configuration file' echo ' --diagnosis :print diagnosis data' echo ' -h --help :help' fi echo ' Copyright 2007-2012 Brother Industries, Ltd' exit 0 fi if [ "$1" = "-l" ] || [ "$1" = "--list" ]; then /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $* exit 0 fi if [ "$1" = "-f" ];then /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $* else /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $*& fi 
It became
 #! /bin/sh if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then ## if [ "$2" = "2" ];then echo ' no option :register all MFCs' echo ' -t (--terminate) :terminate this tool' echo ' -a (--add MFC) :register the specified MFC' echo ' -d (--delete) MFC :exclude the specified MFC' echo ' -p (--passwd) PASSWORD :set the password' echo ' -u (--username) USERNAMR :set the user name' echo ' -l (--list) :list the available MFCs' echo ' -m (--mailto) :mail address (scan to e-mail)' echo ' --refresh :refresh setting' echo ' --reset :reset the configuration file' echo ' --diagnosis :print diagnosis data' echo ' -h --help :help' ## fi echo ' Copyright 2007-2012 Brother Industries, Ltd' exit 0 fi if [ "$1" = "-l" ] || [ "$1" = "--list" ]; then /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $* exit 0 fi if [ "$1" = "-f" ];then /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $* else /opt/brother/scanner/brscan-skey/brscan-skey-0.2.4-0 $*& fi 
I just did not understand why we need the second argument.
We add this script to autoload. Add to /etc/rc.local
 /opt/brother/scanner/brscan-skey/brscan-skey 

And you can run it:
 brscan-skey 

To stop the demon
 brscan-skey -t 

9. Make a script for periodic cleaning of the scan directory
/home/admin/del.sh
 #! /bin/sh work_dir=/srv/scan archiv_dir=/srv/scan/ mkdir -p $archiv_dir ##    ,  -    cd $work_dir mv *.jpg $archiv_dir ## find -maxdepth 1 -type f -mtime +1 -exec mv {} $archiv_dir \; ##   7   cd $archiv_dir find . -type f -mtime +7 -delete 

Script rights are 740

Using cron, you can assign the periodicity of the cleanup script execution. But since every day after working day the server is turned off by briefly pressing the power button, I added to the /etc/acpi/powerbtn.sh file
 ##    /home/admin/del.sh 


A short video demonstrating the operation of the scanner.


Thanks for attention!

Source: https://habr.com/ru/post/187168/


All Articles