LinuxQuestions.org
Have you listened to LQ Radio?
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 10-30-2009, 06:38 PM   #1
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 4
Thanked: 0
script/app to automatically print web page to physical printer when updated


[Log in to get rid of this advertisement]
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!
windows_vista cyberhus is offline  
Tag This Post , ,
Reply With Quote
Old 10-30-2009, 06:56 PM   #2
MBybee
Member
 
Registered: Jan 2009
Distribution: PC-BSD/FreeBSD/Debian
Posts: 137
Thanked: 10
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.
linuxdebian MBybee is offline     Reply With Quote
Old 10-30-2009, 07:26 PM   #3
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 4
Thanked: 0

Original Poster
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?
windows_vista cyberhus is offline     Reply With Quote
Old 10-31-2009, 09:08 PM   #4
MBybee
Member
 
Registered: Jan 2009
Distribution: PC-BSD/FreeBSD/Debian
Posts: 137
Thanked: 10
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 09:10 PM..
freebsd MBybee is offline     Reply With Quote
Old 11-06-2009, 07:45 AM   #5
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 4
Thanked: 0

Original Poster
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!
windows_vista cyberhus is offline     Reply With Quote
Old 11-15-2009, 04:57 PM   #6
cyberhus
LQ Newbie
 
Registered: Oct 2009
Posts: 4
Thanked: 0

Original Poster
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...
linuxubuntu cyberhus is offline     Reply With Quote
Old 11-16-2009, 02:06 PM   #7
MBybee
Member
 
Registered: Jan 2009
Distribution: PC-BSD/FreeBSD/Debian
Posts: 137
Thanked: 10
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
linuxdebian MBybee is offline     Reply With Quote
Old 11-16-2009, 06:22 PM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Puppy
Posts: 2,717
Thanked: 21
ignore me, wrong post!

Last edited by bigearsbilly; 11-16-2009 at 06:24 PM..
freebsd bigearsbilly is offline     Reply With Quote
Old 11-17-2009, 11:26 AM   #9
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: Open Suse, Fedora, Redhat
Posts: 2,272
Thanked: 74
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.
linux theNbomr is offline     Reply With Quote
Old 11-17-2009, 02:44 PM   #10
MBybee
Member
 
Registered: Jan 2009
Distribution: PC-BSD/FreeBSD/Debian
Posts: 137
Thanked: 10
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
linuxdebian MBybee is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


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


All times are GMT -5. The time now is 08:55 AM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration