Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
Links Printer

LPD For Fun and MP3 Playing 122

poop writes "Most true Unix geeks will recognize just how nice LPD is as a distributed queueing mechanism for managing all jobs sent to the printer. But, what most people don't realize is that LPD can be used for other things too. In fact, it can be viewed as a general queueing mechanism with a few added bells and whistles for printers. So let's examine a more interesting use of LPD, an engine for distributed spooling of MP3s." Bruha points out this mirror.
This discussion has been archived. No new comments can be posted.

LPD For Fun and MP3 Playing

Comments Filter:
  • geez (Score:5, Informative)

    by Triumph The Insult C ( 586706 ) on Saturday May 24, 2003 @10:18AM (#6030730) Homepage Journal
    this has been getting a lot of coverage this week (article on deadly, some canadian newspaper, and now here). they did it at the obsd hackathon last year, and again this year.

    lpd is quite cool. i've used it to queue software builds on remote machines where we aren't given ssh accounts. it's pretty slick.
    • lpd is quite cool. i've used it to queue software builds on remote machines where we aren't given ssh accounts.

      This is just another example of the power of simple, 'dumb' design, especially at the low levels of the protocol stack: Unix says that 'everything is a stream of bytes' and so does TCP/IP, having been heavily influenced by Unix. Even though it's called 'Line Printer Daemon', it is written generally enough to be used to queue any stream of bytes. As a transport mechanism, it need not know any

  • So? (Score:4, Interesting)

    by ayf6 ( 112477 ) on Saturday May 24, 2003 @10:19AM (#6030735) Homepage
    The real beauty of this would be if he had written a "print" driver that would allow a remote PC running windows to queue up a song thus utilizing lpd to be a "music" server rather then just an mp3 player hack.
    • by ayf6 ( 112477 )
      I also wanted to add that remotely queuing also would upload the file to the "music" server thus storing it there for later usage.
    • Re:So? (Score:3, Interesting)

      by L0C0loco ( 320848 )
      Well imagine this interfaced to a website where you can browse the available material and "print" tracks to the audio queue. Rather than just playing the audio locally, it adds it to the webacast audio stream you are listening to (a queue for each stream). You can easily monitor the queue/streams from the same website - all without needing to mess with a database. It would also be easy to have a background "DJ" script loading the queue periodically with randomly selected tracks with a low priority. That way
    • Re:So? (Score:3, Interesting)

      by DeadSea ( 69598 ) *
      Its pretty easy to send a file to a unix print queue from Windows: http://gccprinters.com/support/doc/lprutil.html [gccprinters.com]
    • You might be able to do that with samba, by defining a printer or share in your smb.conf with the spool that plays mp3s.

      There was an article a couple months ago in Linux Journal, i believe, with instructions on using a smb-shared "printer" on your linux box to run files through ghostscript in order to get PDFs out.

      I can't try it out right now but i hope this gives someone an idea.
  • by ethnocidal ( 606830 ) on Saturday May 24, 2003 @10:20AM (#6030738) Homepage
    I don't normally do this, but as the site seems to be almost dead within the first three posts, I've duplicated the article content in this post.

    -- article --
    May 23, 2003
    LPD for fun and MP3 playing
    Background

    Most true Unix geeks will recognize just how nice LPD is as a distributed queueing mechanism for managing all jobs sent to the printer. It has a beautiful simplicity to it, and some mean power to go along with it. It's a difficult beast to tame, but once you understand it, everything will start coming out exactly like you want it.

    But, what most people don't realize is that LPD can be used for other things too. In fact, it can be viewed as a general queueing mechanism with a few added bells and whistles for printers. So let's examine a more interesting use of LPD, an engine for distributed spooling of MP3s.
    Motivation

    The main thing that got me started on this quest was seeing these two pictures (one, two) from the c2k3 openBSD hackathon I saw that obviously someone else had figured out how to do it. I sure as heck could also.
    Initial Assessment

    The first stop on my quest was examine the all-knowing seer of the Internet, google. That returned a wonderful page in Swedish about how to do this very task. Unfortunately, my swedish sucks, but thankfully the scripts were written in bash, and the other big thing was just a printcap file.
    Creating a Printcap Entry

    The first thing that you need to do is to create an entry in your printcap file for your shiny new mp3 printer. On most systems this file is /etc/printcap on my redhat 7.3 system (no sound card on the openBSD firewall) it is /etc/printcap.local. You'll want to paste the following snipped of code in there:

    mp3:\ :lp=/dev/null:\ :sd=/var/spool/lpd/audio:\ :if=/usr/local/bin/audiofilter:\ :af=/var/log/audio-acct:\ :lf=/var/log/audio-errs:\ :sh

    Now we'll walk through the entry line by line. I'll ignore the \ at the end of almost every line, that just tells lpd to keep reading because there is more to come. The last line doesn't need the \ obviously.

    * 1: mp3: - the name of your mp3 printer. In this case, just mp3
    * 2: :lp=/dev/null: - we're not hooking this up to a physical device in the normal sense
    * 3: :if=/usr/local/bin/audiofilter: - this is the input filter. I'll show how to create it later.
    * 4: :af=/var/log/audio-acct: - this is the accounting file. You could do some fun stuff with this to monitor who uses the queue the most and what not.
    * 5: :lf=/var/log/audio-errs: - this is the file that errors will be logged to. Well, some errors; not all errors will end up here.
    * 6: :sh - tells it to supress any header information that would normally be sent. This is important or you may get junk before every file which causes audiofilter to fail.

    An Audio Input Filter

    The key to the whole system is that all of the processing is done by input filter. On some platforms this may cause it say that the printing has stalled while a song is playing, but that's not a big deal. There is no output from the input filter, and thus nothing is done after this. You'll want to put the following piece of code on your system as /usr/local/bin/audiofilter:

    #!/bin/bash
    #
    # This script was originally made by Teddy Hogeborn.
    # Small alterations was made by:
    # Peter Lundqvist
    # Patrick Wagstrom
    #
    # This is a "printer filter" for playing audio files

    for arg in "$@"; do
    case "$arg" in
    -d*) dir="${arg#-d}" ;;
    -e*) basefile="${arg#-e}" ;;
    -f*.*) ext="${arg##*.}" ;;
    esac
    done

    mp3player="mpg123 -q -o oss";
    modplayer="mikmod --quiet --playmode 0 --noloops --
  • by koh ( 124962 ) on Saturday May 24, 2003 @10:21AM (#6030741) Journal
    I'm suprised they didn't try to pull this feat on Emacs first though.

    Next in line, "sendmail configuration files used as crypto keys" :)

  • by hrbrmstr ( 324215 ) * on Saturday May 24, 2003 @10:21AM (#6030744) Homepage Journal
    Anyone have any links to some libraries or projects that might use lpd as a transport for generic queueing? Seems like a nice, language-agnostic, non-complex mechanism for cross-system job scheduling, etc. No real security model (though one could adapt something to it), but cool and readily available nonetheless.

    Given what one can do with ghostscript queues, this is not exactly rocket science, but it goes to show the flexibility of *nix once again.

    • Interesting idea. Personally, I would like to see a Win32 client for sending (via explorer, not IE, but explorer) audio files to the remote server. I suspect that this could be done via the Windows printing system but it could get dirty--you'd probably need a custom printer driver.

      Chris
  • Useless... (Score:5, Funny)

    by TedCheshireAcad ( 311748 ) <ted.fc@rit@edu> on Saturday May 24, 2003 @10:21AM (#6030745) Homepage
    ...unless it can be used as a porn queueing mechanism.
  • Funky, but (Score:5, Funny)

    by nich37ways ( 553075 ) <slashdot@37ways.org> on Saturday May 24, 2003 @10:22AM (#6030750) Homepage
    The real problem I see with this is, you will always get some sadistic bastard who spools a ton of *pop* music before disapearing out of ear shot or some fool who doesnt understand how it works and sticks the same song in over and over again.

    Apart form that looks very fun for a small network with shared sound.
    • well, just put some protection code in or whatever... although the further you take the concept you may as well make a whole program (web based or whatever) and forget using LPD
      • although the further you take the concept you may as well make a whole program (web based or whatever) and forget using LPD

        Well, I startet writing something like that in bash. There are still many things to improve, but it's working quite nicely for me: http://muff.sourceforge.net

    • Ah, but thats part of the wonder of lpd. Ever since the old days, people have had the power to monitor and drop items from the queue if they're given permission to do so. Check out lpq and lprm.
  • Article mirror (Score:3, Informative)

    by SILIZIUMM ( 241333 ) on Saturday May 24, 2003 @10:22AM (#6030752) Homepage
    http://pages.infinit.net/pmessier/slashdotted/0001 28.html [infinit.net]

    And enjoy. Don't mod me up though, it would be karma-whoring.

    And wanted to add that the idea isn't new as you can see in this recent thread on deadly.org here [deadly.org] (See post "mp3's playing via lpr?").

  • do tar -xzf myfile.txt.tar.gz | mpage -4 | gs -q -sPRINTER=ljet -sOutputFile=- > /dev/lp0

    • No, most unix geeks would know that you need to add --to-stdout to tar. And what's the point of having a single file in a tarball? Just use gzip or bzip2 directly on the file.
    • Following on from the above 'I don't normally do this...' karma thread....(and sorry for the redundant comment)

      I wouldn't normally do this but OpenBSD really does rock; it's cool (but not surprising) that this has come from the hackathon news. I'm quite sure there'll be lots more interesting stuff to come from the most recent and future ones (with or without funding :)
  • by dpokorny ( 241008 ) on Saturday May 24, 2003 @10:32AM (#6030774)
    This is something I did about five years ago when MP3s where just starting to become popular. It included writing a front-end in Java that was served via an Apache web server on the music host.

    It was actually quite successful and kept my house in 24x7 music for about four years. Unfortunately, I retired all of my lpd-based printers and started using CUPS, so I also killed the mp3 queue too.
  • lpd is nice? (Score:4, Interesting)

    by timeOday ( 582209 ) on Saturday May 24, 2003 @10:37AM (#6030789)
    I don't much like lpd. To me it is one of those crufty old programs that never seems to work right, never gives informative error messages, and whose configuration is arcane. Other nominees: ntp and sendmail. (And yes, I'm sure they're all wonderful once you've mastered them).
    • I couldn't agree with you more. I genuinely tried to install linux for a desktop OS, and ran into more problems with printing than anything else. That and CD burning. Linux is fine for a server, but trying to pass it off as good for much of anything is just plain retarded.
      • I just want to tell you that for me Linux is a better desktop Os than Windows 2000, since my printer (hp 400) isn't even working in Windows, whereas in Linux it prints beautifully.
        Granted the printer is fairly old but so what, I'm not going to buy new hardware just to be able to run Windows.
        You never said when you installed Linux, things are moving pretty fast you now.
        • well I just put win2k back on this morning. When I posted that, I was sick of trying to find the right PPD file in order to make lpd and/or cups work. (I tried both). Then after it coastered 2 cds in a row trying to back up files I had downloaded on the linux install, I threw up my hands in disgust. (My distro was Slack 9 FYI)
          • I wouldn't suggest using Slackware if you're looking for an easy setup. I use Mandrake 9.1 and I haven't had to setup a single device by myself. Personally I don't see the benefits of using Slackware, seems to be a geek thing.
      • This brings a better project to mind... I'd like to set up a CD-burning queue. Anyone know how to accept a stream and burn the CD off the server? Especially with a windows front-end...
      • I genuinely tried to install linux for a desktop OS, and ran into more problems with printing than anything else.

        I had the same troubles until I settled on CUPS and KDE. Absolutely z.e.r.o. problems. This is with high-end (duplexing, finishing, faxing) mopiers and plain-jane inkjets too. Just beware the WinPrinters.

    • To me it is one of those crufty old programs that never seems to work right, never gives informative error messages, and whose configuration is arcane.

      But LPD *IS* simple... The complexity involved is due to the print filters most people use along with LPD. If you have a postscript print (thus need no filter), an amature can setup LPD (referencing the man page) in about 5 minutes.

      All too often I've wished people would think about the consequences of their printfilter design. Ghostscript is fairly lowsy

  • CUPS also (Score:5, Informative)

    by FauxPasIII ( 75900 ) on Saturday May 24, 2003 @10:38AM (#6030791)
    I like CUPS's mechanism for this kind of thing even more. You basically have two components, a filter and a backend. The filter takes in one a few forms of input (mostly postscript, but plain text and some image formats also) and dumps out the native data format of the selected printer model (or just echos the input if you set it as a raw queue). The backend is then responsible for somehow getting it to the printer, either queueing it on the parallel port or sending it out on the network somehow, or anything else.

    Some fun things I've done with backends:

    Network printing over SSH
    Text-to-speech queueing (print your source code to hear it read aloud by festival)
    Dumping into a jpeg as a way of snapshotting any document you might want to save
    Dumping into a PDF with ps2pdf to make your Windows friends feel stupid for buying Distiller =)
  • by hey ( 83763 ) on Saturday May 24, 2003 @10:39AM (#6030794) Journal
    While we're hacking ... how about using DNS zone transfers. Its distributed (everywhere) and its cached until a change occurs. Maybe you'd have to uuencode the info. But what if every .com entry had a few MP3s!
  • by DrWhizBang ( 5333 ) on Saturday May 24, 2003 @10:41AM (#6030801) Homepage Journal
    "/dev/dsp" is on fire!
  • HIgh End Queuing? (Score:3, Insightful)

    by bigattichouse ( 527527 ) on Saturday May 24, 2003 @10:42AM (#6030808) Homepage
    Could this be adapted for a MQ system (say queuing database queries?).. just adding some extra info into the "document", like where the query came from, etc. What kind of load can it handle?
  • by Anonymous Coward on Saturday May 24, 2003 @10:43AM (#6030809)
    I sent my entire playlist to lpd and i've gone through all my paper, is there a way to make it print 4-up to save a few trees? To be honest I don't see the appeal of this....
  • just my two cents: cups has been much nicer in my experience. One of my favorites: lp -o prettyprint -o number-up=2
  • by nurb432 ( 527695 ) on Saturday May 24, 2003 @10:44AM (#6030817) Homepage Journal
    Slashdot REALLY needs to start being more responsible and contacting these people first..

    Sure, report news as needed, but before *linking* ASK them if they can deal with the load.. or the cost after being hit hard..

    This is getting really bad, and i can feel a 'anti-slashdot' movement growing over this sort of thing.
    • yeah sure, like Taco calling the guys up saying : "hey, we're about to link to one of your page and your server may die as a result, your expensive T1 will be DoS'ed to uselessness for 2 hours, and your admin may have to work overtime. Do you mind ?"

      And forget about caching the pages on /. : my news ticker already gets kicked out when it pulls headlines more than twice an hour, so forget about VA authorizing that kind of extra load.
      • What about the poor guys that are self-hosting on dsl/cable and go over their monthly cap.. then socked with a HUGE bill...

        Or the tiny personal web pages that cap # of hits...

    • Yeah, but that would require two things:

      1. For the slashdot crowd to stop regarding "the slashdot effect" as some sort of penis substitute.

      2. For Rob and Taco to actually spend 0.00001 seconds pondering the concepts of "ethics" and/or "professionalism."

      Not gonna happen in a million years.

    • Well, in that case, warn this guy that his page will be slashdotted early next week, when the dupe story gets posted.

      Chris
  • by fobbman ( 131816 ) on Saturday May 24, 2003 @10:46AM (#6030822) Homepage
    ...will it do something like this [turbulence.org]?

  • Huh ? (Score:3, Funny)

    by Moderation abuser ( 184013 ) on Saturday May 24, 2003 @10:46AM (#6030824)
    I just let xmms handle the queueing of music, in a thing called a "play list".

    However, for real geekiness, you should be using gridengine to queue and distribute your mp3s.

  • http://lmo.warcry.com/mp3lpd.php Lazy Link to Mirror [warcry.com] Enjoy
  • by The Fanta Menace ( 607612 ) on Saturday May 24, 2003 @11:06AM (#6030874) Homepage

    ...until you accidentally spool that mp3 to the printer ;)

  • I can imagine hooking LPD up to a 3D renderer like POV-Ray, BMRT, or even Lightwave's new Linux render client, then "printing" TIFF frames from your animation software.

    How cool! I can't wait to try it!
  • by sker ( 467551 ) on Saturday May 24, 2003 @12:16PM (#6031125) Homepage Journal
    I can't BELIEVE the RIAA is trying to shut thus guy down for...

    Oh they're not?

    Well.. How DARE SCO sue this guy for using...

    Err, wait..

    This is an article.. about someone using software technology... to accomplish a task... and there's no litigation involved???

    OH MY GOD!!!!

  • by zdzichu ( 100333 ) on Saturday May 24, 2003 @12:55PM (#6031383) Homepage Journal
    Whoa. My CUPS is right now playing some .ogg files :)

    Steps are simple:
    1. uncomment
    #application/octet-stream
    at the very end of /etc/cups/mime.types

    3. drop this
    ---
    #!/bin/bash

    if [ $# = 0 ] ; then
    echo network audioplay \"Unknown\" \"Audio Player\";
    exit 0;
    fi
    /usr/local/bin/mplayer -really-quiet "$6" >> /dev/null
    ----
    in /usr/lib/cups/backend/ as audioplay
    chmod it +x and restart cups

    4. Add printer in cups:
    name: audio
    location: /dev/null
    description: Hacked Audio-playing CUPS
    device: Audio player
    (if you don't see this device, you probably haven't restarted cups or audioplay is not executable)
    device uri: audioplay://unused/
    make: raw
    model: rawqueue

    4. cat your_favourite.ogg | lpr -r -Paudio
    you can also do
    lpr -Paudio -r song.mp3
    but be careful, lpr likes to delete file after printing.

    5. Prof^WEnjoy!
    • Why the hell is this modded up? The guy just posted code that just might wipe out some poor, unsuspecting newbie's music collection.

      Oh, the hillarity! Great way to convert people to Linux, have them destroy their music collection.

      BTW, this doesn't even work. It will play the first file sent to the queue, and the rest pass simultaneously, like Taco Bell through a Perl coder. Anyone know how to get this code to work so that it actually queues the music files, and isn't just an archaic frontend to mplaye
      • well first off, don't use the -r toggle

        `man lpr` says that it deletes the file, post printing.
        • Oh sh*t. I've misreaded the man of lpr and used '-r' instead of '-l'. Mea culpa, mea culpa, mea maxima culpa.

          But I've noticed lpr tried to delete file (it's hard to do from CD :) and i've wrote a warning in my post.

          And it works for me, queuing like it should.
  • At NOAO [noao.edu] the Unix lpd has long been used as the mechanism for Save the Bits [noao.edu], which is the means by which they and several other observatories archive all of the data acquired at their telescopes.
  • Securitah Warning (Score:3, Interesting)

    by cjsnell ( 5825 ) on Saturday May 24, 2003 @02:13PM (#6031754) Journal

    Beware, these scripts appear to be vulnerable to to un-escaped shell command characters (ie ', ", &, etc) in the filename. The script does not do any validation of the file that is sent to it. Since LPD doesn't do any authentication by default, be very careful about running this stuff on a public-accessible machine.

    Chris
  • From what I understand... xterminals don't really support sound, not in any meaningful way. Could this simple solution be used with a typical x-terminal to provide... well, local sound?
  • A well-designed, well-implemented print spooling system could be useful for other applications. Unfortunately, we don't have one of those yet.

    lpd, lprng, and cups all have a nasty habit of getting into weird states. And lprng and cups can also be a b*tch to configure.

  • In my office we use a one-writer, many-readers database system for timeseries data [fame.com]. But we have many people responsible for small parts of the database, so we needed some way to pool the updates into a single, serial stream. About eight or so years ago, we wrote an update queueing system using PLP, the precursor to LPRng. The thing has worked flawlessly since then, in a production environment supporting dozens of updaters. Print spoolers aren't just for printing anymore :-)
  • Got a mirror up - here [fatalnetwork.com]. It can handle the traffic, don't worry.
  • Back when I was a GNU/newbie, my Red Hat box got 0wn3d by some script kiddie due to a buffer overflow exploit in lpd. I use CUPS now, even though I know LPD is generally very safe. One of those irrational, almost subconscious things, you know? Ahh well, no damage was done, it taught me to keep my software patched and my ports closed, and it gave me a good excuse to rid myself of RPM hell and install Slackware :^)

Talent does what it can. Genius does what it must. You do what you get paid to do.

Working...