Linux Blog

Automated scanning with the shell

Filed under: Shell Script Sundays — TheLinuxBlog.com at 9:25 am on Sunday, July 27, 2008

I recently needed to scan a lot of images on my desktop PC. Unfortunately I am not the owner of an automatic document feed printer, and if I were it wouldn’t have helped this time because the documents I needed to scan were not feed able. XSANE is a great way to scan documents visually in Linux. Its not the easiest to use, but it has plenty of options. Part of the SANE package is scanimage, scanimage can be used from the shell.

The first thing that I did was a few test images with scanimage. I quickly found out that scanimage outputs in pnm format, and at a high resolution if the correct options are used. Once I found out the good options for my scanner (scanimage –resolution 400 > file.pnm) I wrote a quick shell script to scan up to 1000 times or until I don’t give the script any input. To do this, I used a combination of snippets that can be found in this blog column.

Here is a direct link to the script, and the shell script source below

#!/bin/bash
for i in `seq 1 1000`; do
 
#get input line
read inputline;
 
if [ $inputline ]; then
 
#Process Scanned Image in BG
echo Scanning Pg$i;
scanimage --resolution 400 > Pg$i.pnm;
echo Next;
else
exit
fi
 
done;

To use it all I do is execute the script, and I get to scan up to 1000 documents providing I type something after it prompts “Next”, and then hit enter. Once I was done scanning, I just hit enter to stop the script execution and then moved on to manipulating the images with the shell.

Hope this shell script scanning script is useful, if it is then drop me a comment, or if you have any suggestions or it was not at all helpful still drop me a comment.

Man Pages for commands in this post »

xsane
scanimage

4 Comments »

Comment by Mark

December 14, 2011 @ 5:33 pm

Very handy, although for usability I would make it scan again when nothing was entered, and stop when “quit” or “exit” were typed.

I’m interested in doing something similar, which is scanning into a timestamp-named file any time a document is loaded, and wait otherwise. Any idea if that’s possible? I’m guessing it would rely on the hardware supporting that feature, but don’t know what it would be called.

Comment by TheLinuxBlog.com

December 15, 2011 @ 10:57 am

I’m sure it could be done if your scanner has software that could send an event. As for the timestamped file, that is a good idea and would be easy. Could integrate it into the script. I’ll see what I can do. If your scanner doesn’t have software youcould still keep the script running and just hit enter. Stay posted, might have a new one up this Sunday.

Comment by prasad

January 5, 2012 @ 3:22 am

I am using SUSE 11.4 clients and my printer is HP-laserjet1536dnf all in one.i need automatic script scanning.where i mention my hp laserjet1536dnf.please give me script with examples.

thanks give me your help

Comment by TheLinuxBlog.com

January 5, 2012 @ 11:59 pm

If your scanner supports SANE you should be able to use this script.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>