DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 20th October 2008
neurosis neurosis is offline
Fdisk Soldier
 
Join Date: Jul 2008
Posts: 69
Thanked 0 Times in 0 Posts
Default torsmo displaying weather question

Ive been reading on other forums "gentoo and ubuntu" that you can get torsmo to display the current weather. It looks rather simple though I dont know anything about programming or shell scripting. Here is a link to the thread.

http://forums.gentoo.org/viewtopic-t...rsmo+tips.html

Here is the code for the script.

Code:
#!/bin/bash
city="DeWitt"
link=USMI0231.html
file=/tmp/weather.txt
location=http://weather.yahoo.com/forecast/$link

lynx -accept_all_cookies -dump $location > $file
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`
end=`expr $begin + 40`

head -n $end $file > tmp.t
tail -n 41 tmp.t > $file

case $1 in
   Today)  head -n 6 $file | sed '3d' ;;
   Tomorrow)
      begin=`cat -n $file | grep 'Today Tomorrow' | cut -d ' ' -f5`
      end=`cat -n $file | grep 'Extended' | cut -d ' ' -f5`
      num=`expr $end - $begin - 1`
      end2=`expr $begin + 7`

      head -n $end2 $file > tmp.t
      tail -n 3 tmp.t | sed 's/sky/\n sky/' | sed '4d' ;;
   *) exit ;;
esac

rm tmp.t
rm $file
When I run this I get an error.

Code:
$ ./tweather.sh
expr: syntax error
head: illegal line count -- /tmp/weather.txt
Can anyone offer suggestions as to why this isnt working?
Reply With Quote
  #2   (View Single Post)  
Old 20th October 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,148
Thanked 182 Times in 149 Posts
Default

To see where the error is, run the script with debugging enabled
Code:
$ sh -vx ./tweather.sh
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #3   (View Single Post)  
Old 20th October 2008
neurosis neurosis is offline
Fdisk Soldier
 
Join Date: Jul 2008
Posts: 69
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by J65nko View Post
To see where the error is, run the script with debugging enabled
Code:
$ sh -vx ./tweather.sh
Code:
$ sh -vx ./tweather.sh
#!/usr/local/bin/bash
city="Ogden, UT"
+ city=Ogden, UT
link=USUT0020.html
+ link=USUT0020.html
file=/tmp/weather.txt
+ file=/tmp/weather.txt
location=http://weather.yahoo.com/forecast/$link
+ location=http://weather.yahoo.com/forecast/USUT0020.html

lynx -accept_all_cookies -dump $location > $file
+ lynx -accept_all_cookies -dump http://weather.yahoo.com/forecast/USUT0020.html
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`
+ + grep Currently
cat -n /tmp/weather.txt
+ cut -d   -f5
+ begin=
end=`expr $begin + 40`
+ expr + 40
expr: syntax error
+ end=

head -n $end $file > tmp.t
+ head -n /tmp/weather.txt
head: illegal line count -- /tmp/weather.txt
tail -n 41 tmp.t > $file
+ tail -n 41 tmp.t

case $1 in
   Today)  head -n 6 $file | sed '3d' ;;
   Tomorrow)
      begin=`cat -n $file | grep 'Today Tomorrow' | cut -d ' ' -f5`
      end=`cat -n $file | grep 'Extended' | cut -d ' ' -f5`
      num=`expr $end - $begin - 1`
      end2=`expr $begin + 7`

      head -n $end2 $file > tmp.t
      tail -n 3 tmp.t | sed 's/sky/\n sky/' | sed '4d' ;;
   *) exit ;;
esac
+ exit
I dont know what all of this means. I see an expression error?
Reply With Quote
  #4   (View Single Post)  
Old 20th October 2008
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

Maybe change this:
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`

to:
begin=`cat -n $file | grep "Current" | cut -d ' ' -f5`
Reply With Quote
  #5   (View Single Post)  
Old 20th October 2008
neurosis neurosis is offline
Fdisk Soldier
 
Join Date: Jul 2008
Posts: 69
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by ephemera View Post
Maybe change this:
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`

to:
begin=`cat -n $file | grep "Current" | cut -d ' ' -f5`
Worked. That was something very simple too. Sometimes this kind of thing makes me think I lack commons sense skills.

Thank you. I'll test this when I get home
Reply With Quote
  #6   (View Single Post)  
Old 20th October 2008
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

The script needs to be adapted to changes in yahoo's website...

It searches for the word "Currently" in the dumped page... as it doesn't exist, some of the scripts variables don't get properly set.. in the end, kaboom.

Moral of the story: Don't write scripts that assume a page will stay the same forever.

Yahoo offers RSS/XML streams, try writing a script to parse that mess..

Last edited by BSDfan666; 20th October 2008 at 03:45 PM. Reason: ephemera beat me too it.
Reply With Quote
  #7   (View Single Post)  
Old 20th October 2008
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,148
Thanked 182 Times in 149 Posts
Default

Code:
$ sh -vx ./tweather.sh
#!/usr/local/bin/bash
city="Ogden, UT"
+ city=Ogden, UT
link=USUT0020.html
+ link=USUT0020.html
file=/tmp/weather.txt
+ file=/tmp/weather.txt
location=http://weather.yahoo.com/forecast/$link
+ location=http://weather.yahoo.com/forecast/USUT0020.html
The lines not prefixed with a '+' are the source. The '+' lines show the result..
Code:
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5`
+ + grep Currently
cat -n /tmp/weather.txt
+ cut -d   -f5
+ begin=
Here you see that the variable 'begin' has no value.

Code:
end=`expr $begin + 40`
+ expr + 40
expr: syntax error
+ end=
Because 'begin' is empty, the expr command fails and also leaves the variable 'end' empty.
Code:
head -n $end $file > tmp.t
+ head -n /tmp/weather.txt
Here the '+' lines shows that 'end' is empty, so no line count is passed to the head utility.
Code:
head: illegal line count -- /tmp/weather.txt
Not that difficult isn't it?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
external drive partition question + fdisk question gosha OpenBSD General 15 15th June 2009 02:00 PM


All times are GMT. The time now is 10:26 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick