From owner-freebsd-questions@FreeBSD.ORG Sat Jun 27 14:21:04 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D6141065687 for ; Sat, 27 Jun 2009 14:21:04 +0000 (UTC) (envelope-from modulok@gmail.com) Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.239]) by mx1.freebsd.org (Postfix) with ESMTP id 0189A8FC0C for ; Sat, 27 Jun 2009 14:21:03 +0000 (UTC) (envelope-from modulok@gmail.com) Received: by rv-out-0506.google.com with SMTP id l9so615650rvb.3 for ; Sat, 27 Jun 2009 07:21:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=vNe3Iy+PbSTZnlUBmTeRLaeDX2zSyDO6fjAsqg6w2rc=; b=Fns8K/zybA3kbffV5stQGjP2odclg2ZjFzmEugd2YhHvt1oJqmrQDpxndOv55GENUk MaijgHQcTaxDbqWzPTYFL+ZWgOjohv3V0QPWD8hMGHeQ0vE8X6Uom1WyyCYn+oAF6p79 z71XeZM8ifklNJjCJw5Ex4OFX7dgqzr6fA2/c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=KeY4HZgw/B5Eh6982MbDoKef0QyIMSqch8CSUNB8HpnGcaz/i1GonlpQLY8j3u33pY ksfgyuqlsI9elZjgH1pBgwRhHr4iOzrfMZ+1uRJaqvmenk2esWhta7lzJVHynPk3RlxK BuPxOxdztcwDxu9zyCuPKYdaauqgm9VD/OvZw= MIME-Version: 1.0 Received: by 10.141.37.8 with SMTP id p8mr1447781rvj.154.1246112463694; Sat, 27 Jun 2009 07:21:03 -0700 (PDT) In-Reply-To: <4A461551.7090702@realss.com> References: <4A461551.7090702@realss.com> Date: Sat, 27 Jun 2009 08:21:03 -0600 Message-ID: <64c038660906270721v6908c058l53cc574ce43f40a1@mail.gmail.com> From: Modulok To: Zhang Weiwu Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Questions mailing list Subject: Re: scripting suggestion: how to make this command shorter 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: Sat, 27 Jun 2009 14:21:04 -0000 Zhang, Perhaps you could put it into a text file and have cron simply execute the text file. By doing so, you are free to break it up into a more digestible format and start using programming constructs to make your life easier. (Such as storing values in variables, or processing standard input so the script can be called with various URL's and so forth.) Your cron job could then simply execute "/home/you/bin/foo", where 'foo' is whatever you decide to name the script. Is there any specific reason why this has to be all on one line? -Modulok- On 6/27/09, Zhang Weiwu wrote: > Hello. I wrote this one-line command to fetch a page from a long uri, > parse it twice: first time get subject & second time get content, and > send it as email to me. > > $ w3m -dump > 'http://search1.taobao.com/browse/33/n-g,w6y4zzjaxxymvjomxy--------------= --40--commend-0-all-33.htm?at_topsearch=3D1&ssid=3De-s5' > | grep -A 100 =B6=D4=B1=C8 | mail -a 'Content-Type: text/plain; charset= =3DUTF-8' -s > '=3D?UTF-8?B?'`w3m -dump > 'http://search1.taobao.com/browse/33/n-g,w6y4zzjaxxymvjomxy--------------= --40--commend-0-all-33.htm?at_topsearch=3D1&ssid=3De-s5' > | grep =D5=D2=B5=BD.*=BC=FE | base64 -w0`'?=3D' zhangweiwu@realss.com > > > The stupid part of this script is it fetches the page 2 times and parse > 2 times, thus making the command very long. If I can write the command > in a way that the URI only appear once, then it is easier for me to > maintain it. I plan to put it in cron yet avoid having to modify two > places when the URI changes (and it does!). > > How do you suggest optimizing the one-liner? > > By the way I feel it stupid having to wrap the subject by using: > $ mail -s '=3D?UTF-8?B?'`echo $subject | base64`'?=3D' > > instead of > $ mail -s $subject > > Because mail(1), as defined, intelligent user agent, should know the > current locale is UTF-8 and should know UTF-8 header must be base64 > encoded for RFC compatibility. Yet it also should know if mail body is > UTF-8 the header 'Content-Type: text/plain; charset=3DUTF-8' must not be > omitted in case of UTF-8 content. I think this is a bug, as both are > required by RFC. How do you think? > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.o= rg" >