From owner-freebsd-questions Tue Jan 8 16:16:46 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id 5145B37B41D for ; Tue, 8 Jan 2002 16:16:35 -0800 (PST) Received: from hades.hell.gr (patr530-a233.otenet.gr [212.205.215.233]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id g090GUm24082; Wed, 9 Jan 2002 02:16:31 +0200 (EET) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id g090GTg78299; Wed, 9 Jan 2002 02:16:29 +0200 (EET) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 9 Jan 2002 02:16:28 +0200 From: Giorgos Keramidas To: Nils Holland Cc: freebsd-questions@freebsd.org Subject: Re: Questions to all script wizards out there... Message-ID: <20020109001628.GC77687@hades.hell.gr> References: <20011224192919.A89314@tisys.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20011224192919.A89314@tisys.org> User-Agent: Mutt/1.3.23.2i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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///.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///.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 > by one. However, not each month has the same number of days, so assuming > that after 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