Linux Blog

Basic Scripting Snippets Repository

Filed under: Shell Script Sundays — TheLinuxBlog.com at 11:04 pm on Sunday, April 5, 2009

Everyone has their own favorite snippets of code that they use. With command line fu you can share your snippets and look at snippets that other people have posted. I’ve known about it for quite some time and frequently check it out, it’s really shaping up nicely.


Command-Line-Fu is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you’ve been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on and discussed – digg-esque voting is also encouraged so the best float to the top.

I don’t think that you should delete your snippets file, just in-case you don’t have the intrawebs but I think you could get something out of browsing through the highest rated if nothing else.

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.