Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jun 2012 09:23:56 -0700
From:      Devin Teske <devin.teske@fisglobal.com>
To:        Odhiambo Washington <odhiambo@gmail.com>
Cc:        questions <questions@freebsd.org>
Subject:   Re: A bash scripting question
Message-ID:  <1521E29F-C0BC-46A8-A428-FC7183C6E689@fisglobal.com>
In-Reply-To: <CAAdA2WPJkAY7pHau6TCHSLN1faEWS9ZMU1Jq=64YrtmKyLBQpQ@mail.gmail.com>
References:  <CA%2BC6gOgi2kfEpR07Dk0F%2BfbAiJKbDE5NBh9ZrXbkzOB9GrFD5w@mail.gmail.com> <CAAdA2WNnJc%2BWc3guqgPZaTVXneYFvzaAj=z_O-Jzcp45vSZi_Q@mail.gmail.com> <CA%2BC6gOj60PM0WGR9jRdcj0erSNrAzXLQw_gBiyuBQu3nhgiQTg@mail.gmail.com> <CAAdA2WM0KM1yZPZUpON=stc-mLs8zYiPXaP5=EU642UKT0CQOg@mail.gmail.com> <CA%2BC6gOhd4Mk8CkMkODRLvSQThOCx49JSVm4=ihcqFVV1U7C2ig@mail.gmail.com> <CAEobancjDn1TYCETQVw0jAPP2OjVBZX=DUeLEN612nW=WCuqqA@mail.gmail.com> <CAEobane5k%2BdtoWF_cxxZjJQdT4PBfN_44PK=xQgZUvM_9nz77g@mail.gmail.com> <CA%2BC6gOgErgcYWzo=YqpoywscoQQ94zG8OPsJHN6TjtyvMnwXtg@mail.gmail.com> <CAAdA2WO5w_=-OfJQfM803%2BLM%2BGgd5zPmtcYVHCWo-GShAxvQbA@mail.gmail.com> <CA%2BC6gOh25C8mNNjMrVJzWQnnSzYK2p6h6Sh_=k7qHSMzgQ4Vow@mail.gmail.com> <CAAdA2WO88wboMKKMDsL2TYOG9vfk=WfGbx=xA=suySc_qpgnCQ@mail.gmail.com> <CA%2BC6gOgmMJp_OWEOSm=4GFR%2BCDiT6eduEmwSx8u2oogVPCZRww@mail.gmail.com> <CA%2BC6gOioF_wYRXWQWeLUF3FPXj8dP82DAjNh353%2Bp0OpHHcB0Q@mail.gmail.com> <CAAdA2WPJkAY7pHau6TCHSLN1faEWS9ZMU1Jq=64YrtmKyLBQpQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1521E29F-C0BC-46A8-A428-FC7183C6E689>