Power Printing With MagicFilter
Printing with Linux can be a daunting experience—it needn't be. If you really want to become a printing expert, check out the Linux Printing HOWTO, the Linux Printing Usage HOWTO and the lp family of man pages. However, if you just want your Linux box to print text, PostScript, graphics and other formats you throw at it today, read on.
When something sounds too good to be true, it usually is. The one exception to that rule is MagicFilter-1.2, by H. Peter Anvin. It's an extensible, customizable print filter that enables just about any kind of printer to print just about any kind of file automatically.
MagicFilter has two jobs. First, it detects the type of file being printed. It does this by searching for key strings at specific offsets in the file. It does not rely on file names or extensions as indicators of file type. For instance, if the file's first two characters are %!, it's processed as a PostScript file. Other file types, such as gifs, bmps, etc., are detected by similar rules. MagicFilter's second job is to call an appropriate conversion utility to print the file on your specific printer. If you happen to try to print something unprintable, like a binary file, the job is aborted, and you'll be advised (via e-mail) that your file couldn't be printed.
The obvious benefit is that with MagicFilter installed, you can enter the command:
lpr first.txt second.ps third.gif fourth.jpeg\ README.gz
at the prompt, and all five files will spool up and print in fine style. Another perhaps greater benefit is that most packages for Linux come preconfigured with lp or lpr as the default printer. With MagicFilter installed, all of your favorite programs like Pine, Netscape, Applixware, etc. should print fine right out of the box. I'll go into more detail on printing with applications later.
Before you can build MagicFilter, you're going to need some supporting packages. At a minimum, you need the gcc compiler. MagicFilter's Makefile is generated by a script called configure, that scans the directories in your path and caches the locations of any conversion utilities that it finds. If configure doesn't find some of the utilities, MagicFilter will build anyway, but without the ability to print some file types. Table 1 shows the support packages needed for varying levels of file printing ability.
The staircase effect mentioned in Table 1 occurs when a printer omits the carriage return from end-of-line sequences. If you want to see the staircase effect in action, send a short text file directly to your printer device by running this example (substituting your lp device name):
cp /etc/group /dev/lp1
Decide what level of robustness you need in MagicFilter, install those supporting packages, then build magicfilter. I have listed some sources for these packages at the end of this article.
All right, let's assume you have all your support packages identified and installed somewhere in your path. You've obtained the file magicfilter-1.2.tar.gz and as root, moved it to a suitable location. (I always use /usr/local.) Unpack the file with this command:
tar -xzf magicfilter-1.2.tar.gz
This command unpacks MagicFilter into the newly-created directory /usr/local/magicfilter-1.2. Change directory to magicfilter-1.2, and run the configure script. Note the output displayed on your screen; you will probably see a few packages that configure didn't find. Peter Anvin assures me that if you have all the packages shown in Table 1 installed and in your path, you will build a fully-functional magicfilter program. Some of the packages searched for have been replaced (in functionality, at least) by newer ones in the support packages. Anyway, now run make; next, run make<\!s>install. Afterwards, the directory /usr/local/magicfilter-1.2/filters will contain about 40 scripts for just about any printer you are likely to encounter. The actual magicfilter binary may be in /usr/local/bin. What you do at this point is copy or move the script(s) for your printer(s) to /usr/local/bin. For example, if you have a Canon BJ-200ex printer, your script is bj200-filter. Some printers may not have a script per se, but there should be a script that works for almost any printer.
Optionally, you can run make<\!s>install_filters, and all the scripts will be copied to /usr/local/bin. It's worth noting at this point that /usr/local/bin (or wherever you've installed MagicFilter) does not need to be in your path. When we reference these files next, we will use absolute path names.
Since I'm writing about Linux, which uses the BSD printing system, I will only address the Linux-specific installation in the /etc/printcap file. Be advised that not all flavors of Unix implement this printing system. Edit the /etc/printcap file and weave in a call to your printer's script as an input filter. Here is an example for a system with two printers, a HP LaserJet 4 and a HP DeskJet 550C on /dev/lp1 and /dev/lp2, respectively:
pencil|lp|PostScript|ljet4|HP LaserJet 4:\ :lp=/dev/lp1:sd=/var/spool/lpd/pencil:sh:mx#0:\ :if=/usr/local/bin/ljet4-filter: crayon|dj550c|color|HP DeskJet 550C:\ :lp=/dev/lp2:sd=/var/spool/lpd/crayon:sh:mx#0:\ :if=/usr/local/bin/dj550c-filter:
The syntax for the /etc/printcap file is a subject in itself. See the Linux Printing-HOWTO a complete description. Peter points out, “Note the alias `lp' for the default (text) printer, and `PostScript' for the preferred PostScript printer.”
Next, kill and restart your lpd (print demon). Mine killed okay, but it wouldn't restart properly; so, I rebooted. Following the reboot, lpd was indeed running again.
Practical Task Scheduling Deployment
July 20, 2016 12:00 pm CDT
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.Register Now!
- Interview with Patrick Volkerding
- Google's SwiftShader Released
- Tech Tip: Really Simple HTTP Server with Python
- SuperTuxKart 0.9.2 Released
- Non-Linux FOSS: Caffeine!
- My +1 Sword of Productivity
- Parsing an RSS News Feed with a Bash Script
- SUSE LLC's SUSE Manager
- Work the Shell - Analyzing Log Files
- SourceClear Open
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide