Date: Wed, 9 Jan 2002 02:16:28 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Nils Holland <nils@tisys.org> Cc: freebsd-questions@freebsd.org Subject: Re: Questions to all script wizards out there... Message-ID: <20020109001628.GC77687@hades.hell.gr> In-Reply-To: <20011224192919.A89314@tisys.org> References: <20011224192919.A89314@tisys.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2001-12-24 19:29:19, Nils Holland wrote: > Hi folks, > > there are many things that I'd like to eventually learn, for example > writing advanced shell scripts. Right now, I'd like to set up a script for > a particular purpose, but I don't really know how to go about it. > > Here's what this script should do: > > I would like the script to use wget in order to fetch the program listing > of a radio station from the station's website. I would like to have seven > days fetched in advance. > > Now, the URL always looks like this: > http://www.dradio.de/dlf/vorschau/<year>/<month>/<day>.html > > So in order to make wget fetch today's program, I'd run it like this: > > wget -options http://www.dradio.de/dlf/vorschau/2001/12/24.html > > That's the theory, but how do I tell my shell script to do that? I have > two problems, one of which is probably easy to solve, while the other is > a little tough: > > 1) The shell script would have to have a look at today's date and construct > the appropriate URL. It would probably have to obtain the output of date > and assign the year, month and day values to some variables, and then > create the http://www.dradio.de/dlf/vorschau/<year>/<month>/<day>.html URL. > Now, any ideas how to get that done in a script? > > 2) As I said, I'd like to get seven days fetched in advance. An easy way to > do that would be to simply loop multiple times, always incrementing <day> > by one. However, not each month has the same number of days, so assuming > that after <day> has reached 31 it should start from 1 again is not always > accurate. I guess handling this in a shell script would be a fairly hard > thing to do, but if someone has any ideas if it's (easily) possible, I'd > like to know it. I like fetch(1) for making checks like this. Try it out, in a command like the one below: % fetch -o /dev/null http://host/nonexistent.html || echo FAILED Since fetch(1) knows to speak HTTP and FTP, you don't need to do ``black magic'' to make shell scripts find out if a given URL exists. It's all a matter of: URL="some url" fetch -o /dev/null "${URL}" 2>/dev/null if [ $? -eq 0 ]; then # the URL works else # skip this one. fi Easy, isn't it? :) - Giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020109001628.GC77687>