From owner-freebsd-questions@FreeBSD.ORG Thu Jun 21 16:24:24 2012 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 472021065670 for ; Thu, 21 Jun 2012 16:24:24 +0000 (UTC) (envelope-from Devin.Teske@fisglobal.com) Received: from mx1.fisglobal.com (mx1.fisglobal.com [199.200.24.190]) by mx1.freebsd.org (Postfix) with ESMTP id 0040D8FC16 for ; Thu, 21 Jun 2012 16:24:23 +0000 (UTC) Received: from smtp.fisglobal.com ([10.132.206.31]) by ltcfislmsgpa02.fnfis.com (8.14.4/8.14.4) with ESMTP id q5LGODTG008984 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Thu, 21 Jun 2012 11:24:23 -0500 Received: from [10.0.0.105] (10.14.152.61) by smtp.fisglobal.com (10.132.206.31) with Microsoft SMTP Server (TLS) id 14.2.283.3; Thu, 21 Jun 2012 11:23:58 -0500 MIME-Version: 1.0 (Apple Message framework v1257) Content-Type: text/plain; charset="windows-1252" From: Devin Teske In-Reply-To: Date: Thu, 21 Jun 2012 09:23:56 -0700 Content-Transfer-Encoding: quoted-printable Message-ID: <1521E29F-C0BC-46A8-A428-FC7183C6E689@fisglobal.com> References: To: Odhiambo Washington X-Mailer: Apple Mail (2.1257) X-Originating-IP: [10.14.152.61] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.7.7855, 1.0.260, 0.0.0000 definitions=2012-06-21_03:2012-06-21, 2012-06-21, 1970-01-01 signatures=0 Cc: questions Subject: Re: A bash scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Devin Teske List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2012 16:24:24 -0000 On Jun 21, 2012, at 6:40 AM, Odhiambo Washington wrote: > How Can I simplify/perfect the following script, so that I read _ALL_ the > lines in the file and act on the content as shown below, so that I do not > have to specifiy an action per line? >=20 > This below is doing exactly what i need BUT reading one line at a time > untill the 10th line, if i want more i add manually... > This might help some1 someday! But if there is a way to perfect it please > do so..... >=20 > #!/usr/local/bin/bash >=20 > smsfile=3Demail_to_sms > `grep Subject /var/spool/mail/sms >>$smsfile` > if [[ -s $smsfile ]] ; then > cat /dev/null > /var/spool/mail/sms > sed -i 's/Subject: //g' $smsfile > echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D1 > {print $1}' $smsfile` > echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D2 > {print $1}' $smsfile` > echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D3 > {print $1}' $smsfile` > echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D4 > {print $1}' $smsfile` > echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D5 > {print $1}' $smsfile` > echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D6 > {print $1}' $smsfile` > echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D7 > {print $1}' $smsfile` > echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D8 > {print $1}' $smsfile` > echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D9 > {print $1}' $smsfile` > echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR=3D= =3D10 > {print $1}' $smsfile` > else > echo "***********Sorry the SMS FILE "$smsfile" is empty.************" > fi > gammu-smsd start > cat email_to_sms >> email_to_sms2 > cat /dev/null > email_to_sms >=20 Try the following=85 #!/bin/sh smsfile=3Demail_to_sms spoolfile=3D/var/spol/mail/sms grep Subject "$spoolfile" >> "$smsfile" if [ -s "$smsfile" ]; then : > "$spoolfile" sed -e 's/Subject: //g' "$smsfile" | awk ' { if (NR > 10) exit print | "/usr/bin/gammu --sendsms TEXT " $1 }' else echo "***********Sorry the SMS FILE "$smsfile" is empty.************" fi gammu-smsd start cat "$smsfile" >> email_to_sms2 : > "$smsfile" --=20 Devin _____________ The information contained in this message is proprietary and/or confidentia= l. If you are not the intended recipient, please: (i) delete the message an= d all copies; (ii) do not disclose, distribute or use the message in any ma= nner; and (iii) notify the sender immediately. In addition, please be aware= that any message addressed to our domain is subject to archiving and revie= w by persons other than the intended recipient. Thank you.