From owner-freebsd-questions@FreeBSD.ORG Thu Dec 8 23:42:54 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EA90A16A422 for ; Thu, 8 Dec 2005 23:42:54 +0000 (GMT) (envelope-from MTaylor@bytecraft.com.au) Received: from wolf.bytecraft.au.com (wolf.bytecraft.au.com [203.39.118.1]) by mx1.FreeBSD.org (Postfix) with ESMTP id D25E143D7D for ; Thu, 8 Dec 2005 23:41:44 +0000 (GMT) (envelope-from MTaylor@bytecraft.com.au) Received: from localhost (localhost [127.0.0.1]) by wolf.bytecraft.au.com (8.12.11/8.12.11) with ESMTP id jB8Nf3rq098588; Fri, 9 Dec 2005 10:41:03 +1100 (EST) (envelope-from MTaylor@bytecraft.com.au) Received: from wolf.bytecraft.au.com ([127.0.0.1]) by localhost (wolf.bytecraft.au.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 97709-04-5; Fri, 9 Dec 2005 10:41:03 +1100 (EST) Received: from svmarshal.bytecraft.au.com ([10.0.0.4]) by wolf.bytecraft.au.com (8.12.11/8.12.11) with ESMTP id jB8NeDmw098531; Fri, 9 Dec 2005 10:40:13 +1100 (EST) (envelope-from MTaylor@bytecraft.com.au) Received: from svmailmel.bytecraft.internal (Not Verified[10.0.0.24]) by svmarshal.bytecraft.au.com with MailMarshal (v5, 0, 3, 78) id ; Fri, 09 Dec 2005 10:40:12 +1100 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Date: Fri, 9 Dec 2005 10:40:12 +1100 Message-ID: <04E232FDCD9FBE43857F7066CAD3C0F105438E@svmailmel.bytecraft.internal> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: simple shell script Thread-Index: AcX7twvp3h524fsVSmiweyQtXJw5zgAl4siw From: "Murray Taylor" To: "Beecher Rintoul" , "Martin Cracauer" Cc: Dan Nelson , freebsd-questions@freebsd.org Subject: RE: simple shell script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Dec 2005 23:42:55 -0000 Beech, For what it is worth, and if you are interested in=20 another method, here is a ruby script that I found=20 somewhere and tweaked up a bit more. (Probably not the best ruby, but it was my learning effort) It is called by cron, and does a website 'connectivity' test, ie it attempts to get the specified page. The script=20 then generates a go/nogo email and exits. This was built to monitor a web site at an ISP that was=20 having serious brain damage with managing the DNS records (they deleted the active list...;-( ) And it is still running as a health check to this day... Run it _without_ the -v option and it will only email when the remote site has a problem... The ruby script ----------------------8<---------------------------- #!/usr/local/bin/ruby require 'getoptlong' require 'open-uri' require 'net/smtp' if ARGV.empty? then =20 puts "usage: check_url.rb [-v] [-m emailaddr] " =20 exit 1 end # specify options opts =3D GetoptLong.new( =09[ "-v", GetoptLong::NO_ARGUMENT ], =09[ "-m", GetoptLong::REQUIRED_ARGUMENT ] ) smtp_host =3D "smtp.example.com" from =3D "root@example.com" url =3D "" message =3D "" flag =3D 0 verbose =3D 0 # default this to =3D "operator@example.com" # process args opts.each do |opt, arg| =09case opt =09 when '-v' =09 verbose =3D 1 =09 when '-m' =09 to =3D arg =09end end # test again, did we clobber all the args ? if ARGV.empty? then =20 puts "usage: check_url.rb [-v] [-m emailaddr] " =20 exit 1 end # get the url in question url =3D ARGV[0] subject=3D"Web monitor alert re #{url}" # go and test the site begin =20 page =3D open(url).read =20 if page =3D~ /Error|Exception/ =20 message =3D "#{url} has returned either Error or Exception" =09flag =3D 1 =20 end rescue =20 message =3D "#{url} Unavailable\n - #{$!.message}" =20 flag =3D 2 end case flag =09when 0 =09 if verbose =09 mail =3D < -----Original Message----- > From: owner-freebsd-questions@freebsd.org=20 > [mailto:owner-freebsd-questions@freebsd.org] On Behalf Of=20 > Beecher Rintoul > Sent: Thursday, December 08, 2005 4:17 PM > To: Martin Cracauer > Cc: Dan Nelson; freebsd-questions@freebsd.org > Subject: Re: simple shell script >=20 > On Wednesday 07 December 2005 07:33 pm, Martin Cracauer wrote: > > Dan Nelson wrote on Wed, Dec 07, 2005 at 09:52:55PM -0600: > > > In the last episode (Dec 07), Beecher Rintoul said: > > > > I'm trying to write a simple shell script that will=20 > launch a program > > > > (in this case lynx), wait 60 seconds and then kill it.=20 > I can get it > > > > to launch the program, but it seems to ignore anything=20 > after that. I > > > > am not a programmer so does anyone have a suggestion on=20 > this script? > > > > Any help would be appreciated. > > > > > > You need to background it so your script keeps running: > > > > > > #! /bin/sh > > > # Launch program > > > lynx & > > > # Store its processid for later > > > pid=3D$! > > > # 60 seconds > > > sleep 60 > > > # Kill backgrounded process > > > kill -9 $pid > > > > This is probably not what Beecher wants, he/she probably needs the > > lynx in the foreground. > > > > In a pure shell script that is difficult because you cannot get the > > pid of a foreground process without reverting to `ps` which is not > > sportish. > > > > It's better to use a dedicated timeoput mechanism, e.g.: > > http://cracauer-forum.cons.org/forum/cratimeout.html > > > > Then you can do `cratimeout 60000 lynx` > > > > Martin >=20 > Thanks to you both, I missed the background option. Actually=20 > it just needs to=20 > run in the background to log some hits on a free webserver=20 > that I use for=20 > testing. I forget and they will cancel my account if there's=20 > no traffic for a=20 > month. The timeout also looks interesting and I'll look into it. >=20 > Beech >=20 > --=20 >=20 > -------------------------------------------------------------- > ------------------------- > Beech Rintoul - System Administrator - akbeech@gmail.com > /"\ ASCII Ribbon Campaign | NorthWind Communications > \ / - NO HTML/RTF in e-mail | 201 East 9th Avenue Ste.310 > X - NO Word docs in e-mail | Anchorage, AK 99501 > / \ - Please visit Alaska Paradise - http://akparadise.byethost33.com > -------------------------------------------------------------- > ------------------------- >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 >=20 > ***This Email has been scanned for Viruses by MailMarshal.*** >=20 --------------------------------------------------------------- The information transmitted in this e-mail is for the exclusive use of the intended addressee and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of it, or the taking of any action in reliance upon this information by persons and/or entities other than the intended recipient is prohibited. If you received this in error, please inform the sender and/or addressee immediately and delete the material.=20 E-mails may not be secure, may contain computer viruses and may be corrupted in transmission. Please carefully check this e-mail (and any attachment) accordingly. No warranties are given and no liability is accepted for any loss or damage caused by such matters. --------------------------------------------------------------- ***This Email has been scanned for Viruses by MailMarshal.***