script/app to automatically print web page to physical printer when updated
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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.
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!
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...
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.