Is there a neater way to do this? (bash script)
Hi everyone,
I recently wrote this script to gab a weather radar image for the gnome panel weather applet. (I have to use the script because the images name is constantly changing to reflect date and time). I was really hoping to do the entire process as one long pipe but was unable to figure out a way to get the properly formated URL to the last wget command that way.. So figured I'd ask people more experienced then I. Script Follows: #!/bin/bash # # get the weather pic #save the first part of the URL echo -n http://weatheroffice.ec.gc.ca/data/radar/temp_image/ > foo # get the webpage and grep out the name of the .gif.. appent to URL wget -O - http://weatheroffice.ec.gc.ca/radar/index_e.html?id=wkr | grep -m 1 -o -ie wkr_cappi.*\.gif >> foo #grab the .gif and save it with a standard name wget -i foo -O weather.gif # clean up rm foo I would love input on how to make this one long pipe or use Variables to avoid the need for Foo (actually that one I could probably work out on my own.. but I'm still open to hearing input on it as I'm sure there are much more finessed ways then what I'm likely to come up with at this point.). Thanks in advance Freemor |
I don't do much shell scripting, but you could do it in Perl easy enough (Perl rules ;) ).
Code:
#!/usr/bin/perl # perl -MCPAN -e 'install LWP::Simple' -Scruff |
Also, lots of people use lynx (test-based browser) for stuff like this from shell scripts. Gimme a sec and I'll give it a try.
|
Here you go:
Code:
#!/bin/bash -Scruff |
Scruff, thanks for the feedback. With a little testing I've gotten it down to one line, no variables, and no temp files. Great!! The end result looks like this:
#!/bin/bash # # get the weather pic wget http://weatheroffice.ec.gc.ca/data/radar/temp_image/`lynx -dump http://weatheroffice.ec.gc.ca/radar/index_e.html?id=wkr | grep -m 1 -o -ie wkr_cappi.*\.gif` -O weather.gif That basically achievies the one pipe type result I was looking for.. knew I kept Lynx around for a reason (several actually). Your feedback was the nudge in the right direction that I needed |
Excellent! Glad to help :)
|
Scruff
The following script is scripting language, I hope. ------------------------------------------------------- #!/bin/bash URL=http://weatheroffice.ec.gc.ca/radar/index_e.html?id=wkr IMAGE=`lynx -dump $URL | grep -m 1 -o -ie wkr_cappi.*\.gif` # print image name echo $IMAGE ------------------------------------------------------- Please tell me if I am wrong. |
Quote:
|
Scruff
Thanks for the reply. I don't know much about Perl programming. If this is a shell script, I want to run on my computer. Of course I will find some other URL than what is in the program. I know some scripting language. If you are telling me this is a shell script, I will try it. |
All times are GMT -5. The time now is 12:20 PM. |