![]() |
|
|||||||
| FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
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
Code:
$ ./tweather.sh expr: syntax error head: illegal line count -- /tmp/weather.txt |
|
|||
|
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 |
|
|||
|
Quote:
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 see an expression error?
|
|
|||
|
Quote:
Thank you. I'll test this when I get home |
|
|||
|
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. |
|
|||
|
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 Code:
begin=`cat -n $file | grep "Currently" | cut -d ' ' -f5` + + grep Currently cat -n /tmp/weather.txt + cut -d -f5 + begin= Code:
end=`expr $begin + 40` + expr + 40 expr: syntax error + end= Code:
head -n $end $file > tmp.t + head -n /tmp/weather.txt Code:
head: illegal line count -- /tmp/weather.txt
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |