LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-02-2008, 07:09 PM   #1
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Rep: Reputation: 15
Print web pages with a cron job


Hi I just set up a print server with cups and samba, it works great. Now I want to take it a step further and print out a weather report everyday at 6:00 am. The problem isn't the cron job but the command itself, I want to print this page http://printer.wunderground.com/cgi-...st?query=60045.

I have already tried the lp command and it didn't work, anybody have an idea?


Thanks in advance.
 
Old 07-02-2008, 07:37 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
This is a good problem.

It is easy enough to perform via command line, as in :

lynx http://printer.wunderground.com/cgi-...st?query=60045

where you also provide keystroke config file to drive the print screen item.

Doing the same with a GUI browser requires that your script launches the browser (easy enough), and then there needs to be a mechanism to that performs the menu actions (File->Print, OK, etc.). Others have expressed their desire to have such a command line feature: http://wiki.mozilla.org/Firefox/Feat...rming:Printing

There might be GUI macro recorders and playback for your Desktop, but others will have to help out with this once you give more details about your desktop environment.
 
Old 07-02-2008, 07:45 PM   #3
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
Basically I am just running debian with a GUI that I believe is gnome, all I want to do is print out that exact page with a command line command. Unfortunately the lynx command you gave me just spits back an unknown command error, but yeah I don't want to print through a browser unless command line printing changes the way the page looks.


Thanks for your response.
 
Old 07-02-2008, 07:51 PM   #4
Greenfuse
Member
 
Registered: Nov 2004
Distribution: gentoo, arch centos
Posts: 165

Rep: Reputation: 24
htmldoc --webpage -f weather.pdf http: //printer.wunderground.com/cgi-bin/findweather/getForecast?query=60045 ; lp weather.pdf

you might need to install htmldoc

Last edited by Greenfuse; 07-02-2008 at 07:55 PM. Reason: I put a space between the http: and the // to stop it from formatting automatically as a link
 
Old 07-02-2008, 07:56 PM   #5
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I am not aware of any command line operations you can send to (your as of yet unknown) browser to cause it to print.

The lynx command works fine. Be sure to use the correct URI, not the abbreviated on shown above. I tried it. The output certainly is different via command window - take a look at it to see if it meets your needs. If it does, navigate to its Print area and print a page. See if that is acceptable. If so, you can script those operations using lynx -cmd_script=inputfile, where you fill in the correct key sequence in inputfile.
 
Old 07-02-2008, 08:07 PM   #6
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
ah I see lynx is a command line browser, sorry I wasn't following you.... Ok let me try that and see what happens
 
Old 07-02-2008, 08:50 PM   #7
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
The other thing I was thinking is if I could use wget to download the file and then print it?
 
Old 07-02-2008, 08:55 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
wget will download the HTML page, but not render it.
 
Old 07-02-2008, 09:58 PM   #9
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
yeah just figured that out, so there is no way to render it once I've downloaded it? other than using a browser..... because I can't get lynx to print to my printer... I was also looking at this, what do you think?

http://khtml2png.sourceforge.net/index.php?page=about

Last edited by Exutable; 07-02-2008 at 10:00 PM.
 
Old 07-02-2008, 10:07 PM   #10
Greenfuse
Member
 
Registered: Nov 2004
Distribution: gentoo, arch centos
Posts: 165

Rep: Reputation: 24
htmldoc will download and convert it to a postscript or pdf for printing.
 
Old 07-02-2008, 10:18 PM   #11
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Sure, there are plenty of programs that can convert HTML into various formats - too many to list. I guess it comes down to where do you stand in the spectrum from "Exactly Like the Web Page" to "Just the Data". If you just want the data, use wget, and a fast htmltotext converter and push it through a filter to strip out what you don't want.
 
Old 07-02-2008, 10:25 PM   #12
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
Could I then print from there? that might be a solution huh?
 
Old 07-02-2008, 10:37 PM   #13
Exutable
LQ Newbie
 
Registered: Mar 2005
Posts: 22

Original Poster
Rep: Reputation: 15
Ok solid I got it converted and printed the only issue is the pictures for the forecast but that's not even that big of a deal now all I have to do is write the script and the cron job, would I make the script as an sh file?
 
Old 07-02-2008, 11:07 PM   #14
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Include the wget options: --convert-links and --page-requisites. This will download the images and convert the links to local images.

You can use any scripting language you want. The program just needs to be executable:

--- [ myweatherprint ] ---
Code:
#!/bin/bash

LINK='http://printer.wunderground.com/cgi-bin/findweather/getForecast?query=60045'

wget --convert-links \
     --page-requisites \
     --no-directories \
     --no-host-directories \
     -P/var/tmp/weatherdownload \
     "$LINK"


htmltodoc '/var/tmp/weatherdownload/getForecast?query\=60045'
--- [ cut ]

Add your printing statement to the above script.
Code:
chmod a+x myweatherprint

Last edited by Mr. C.; 07-02-2008 at 11:08 PM.
 
Old 07-03-2008, 12:03 AM   #15
Greenfuse
Member
 
Registered: Nov 2004
Distribution: gentoo, arch centos
Posts: 165

Rep: Reputation: 24
Whether you want to have an executable sh file or to place the commands in your crontab file is a matter of taste and probably depends on how many commands you are using. If entering them straight into crontab, a simple colon between commands keeps them on one line. (as per my first post)
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
regular print job using cron or something ? bigjohn Linux - Software 8 03-31-2005 09:14 PM
adding new cron job via web Bake-SaleNet Linux - Software 3 04-07-2004 06:31 AM
cron job to print message to all ehpserver Linux - Newbie 1 02-28-2004 09:08 PM
save daily from cron job the whole Web servers data cccc Linux - General 2 09-09-2003 01:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:48 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration