LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-30-2009, 05:38 PM   #1
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Rep: Reputation: 0
script/app to automatically print web page to physical printer when updated


Hi,
I have to make a quite unusual setup that I don't know how to go about. I have a web page (lets say an ordinary html-page) that is updated once a minute or so. I want the setup to automatically (no clicking on buttons or the like ) print the latest version of this web page on an ordinary printer (lets say it is a printer connected to a PC via network).

Before I get my hands too dirty I would like to hear your suggestions for a setup. My available hardware are 3 PC's with following OSs: Ubuntu, Ubuntu Server and Windows vista home editon + a laser printer (hp 1022).

I considered making some sort of batch-script to run on a windows vista machine but I don't have too much experience with vbscript and vista-programming and I would prefer a linux/Ubuntu-setup. I have some experience with PHP, javascript and a bit of java, but I am really in doubt how to solve the task with these languages.

Suggestions are more than very welcome!
 
Old 10-30-2009, 05:56 PM   #2
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Do you want the website to print for everyone or just for you? There is a way to do that on the host side via javascript/etc.

Depending on what you use from the client side you could pipe from wget to the printer or something like that.
 
Old 10-30-2009, 06:26 PM   #3
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Original Poster
Rep: Reputation: 0
just for me...

The setup is meant to print only for me. So you advice me to install wget, make some kind of script and download the web page?
 
Old 10-31-2009, 08:08 PM   #4
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by cyberhus View Post
The setup is meant to print only for me. So you advice me to install wget, make some kind of script and download the web page?
Yup. For example, a script like this will print a web page to a printer every X seconds:
Code:
#!/usr/bin/bash
while [ 0 -lt 1 ]
do
wget -qO- http://www.example.com | lpr
sleep 30
done
Depending on how you set up your printer, you may want to change that lpr command to go to whatever printer you're using, with whatever options you like. Just sending straight to lpr like that goes to the default printer with no switches.

Last edited by MBybee; 10-31-2009 at 08:10 PM.
 
Old 11-06-2009, 06:45 AM   #5
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MBybee View Post
Yup. For example, a script like this will print a web page to a printer every X seconds:
Code:
#!/usr/bin/bash
while [ 0 -lt 1 ]
do
wget -qO- http://www.example.com | lpr
sleep 30
done
Depending on how you set up your printer, you may want to change that lpr command to go to whatever printer you're using, with whatever options you like. Just sending straight to lpr like that goes to the default printer with no switches.
Nice and simple code - great! I feared the worst. Actually I only want to print if the file has changed since last - it seems like the "-N" parameter for wget would be useful here.

I will try to make it work this weekend, thanks so far!
 
Old 11-15-2009, 03:57 PM   #6
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Original Poster
Rep: Reputation: 0
I got a good step further - the script you suggested works fine. Now I just need to tweak it a bit, so that it only prints when the web page is updated and I also need to format it, so it doesn't print out the html-tags. I guess awk or sed could help me here. I am not sure how to setup the condition for the timestamp change, though...
 
Old 11-16-2009, 01:06 PM   #7
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by cyberhus View Post
I got a good step further - the script you suggested works fine. Now I just need to tweak it a bit, so that it only prints when the web page is updated and I also need to format it, so it doesn't print out the html-tags. I guess awk or sed could help me here. I am not sure how to setup the condition for the timestamp change, though...
You could try doing it in two steps -
1) Do the wget to a file with a timestamp.
2) Compare the file with the previous file (diff), print if different. Delete the previous file.

Regarding the stripping the html tags, yes, you could use perl, sed, awk. Whatever. There is actually already a perl module for this, so that might simplify things: http://search.cpan.org/~kilinrax/HTM...-1.06/Strip.pm
 
Old 11-16-2009, 05:22 PM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,269

Rep: Reputation: 165Reputation: 165
ignore me, wrong post!

Last edited by bigearsbilly; 11-16-2009 at 05:24 PM.
 
Old 11-17-2009, 10:26 AM   #9
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,390
Blog Entries: 2

Rep: Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900Reputation: 900
Use the wget -N method to determine changes, and once you see that there is new data, grab the formatted page with lynx -dump.
--- rod.
 
Old 11-17-2009, 01:44 PM   #10
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by theNbomr View Post
Use the wget -N method to determine changes, and once you see that there is new data, grab the formatted page with lynx -dump.
--- rod.
Never tried using lynx -dump. I'm going to go play with that!
Learn something new every day
 
Old 08-17-2010, 05:08 AM   #11
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Hi Linuxquestions,
just wanted to update you on the project related to this issue. We managed to make a matrix printer print out every time someone writes on the blog, you can see how it looks in this video:

http://www.youtube.com/watch?v=mxnbYFsX3I0

Thanks again for your help!
 
  


Reply

Tags
printer, script, ubuntu


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic web page app madivad Programming 4 03-17-2008 11:21 AM
print test page stops automatically jazz999 Linux - Hardware 1 09-16-2007 03:27 AM
web page app Kamikazee Linux - Software 6 11-15-2005 06:22 AM
printer will print test page but nothing else deftones Linux - Newbie 1 03-21-2005 08:52 PM
Which is the best Web page creation app for a newbie? Stevetgn Linux - Software 10 07-05-2004 11:32 AM


All times are GMT -5. The time now is 10:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration